Rust tips @rust@octodon.social
Follow

When implementing a custom iterator you may be tempted to reuse the same buffer for each element for efficiency. Unfortunately, that won't compile, because the `Iterator` trait allows such usage:

let one = iter.next();
let two = iter.next();

If you could return iterator's internal buffer, then `one`'s content would be overwritten when `two` is created.

Use `StreamingIterator` instead: github.com/sfackler/streaming-

· Web · 3 · 6