> The only way to implement .finished() non destructively (so that, when > returning false, it does not eat an element) is with a Peekable iterator as > in this pull request: > > https://github.com/mozilla/rust/pull/8428 > > Then .finished() is .peek().is_none().
If you loop all the way through the iterator without calling peek(), then when you call peek() after that, it's going to call next() on the underlying iterator after it has already returned None. Without guarantees discussed earlier in this thread about what happens if you call next() on an iterator that has already returned None once, this won't necessarily work--and as referenced earlier, those guarantees cannot be assumed. > But this is unnecessary overhead if you don’t otherwise use .peek(). The > for-loop already knows how it exited. It only "knows" if something explicitly makes it know. This boils down to one of two things: either the boolean flag approach as discussed earlier, or the compiler turning every "break" in the block into an explicit call to the else block. > > -- > Simon Sapin > _______________________________________________ > Rust-dev mailing list > Rust-dev@mozilla.org > https://mail.mozilla.org/listinfo/rust-dev _______________________________________________ Rust-dev mailing list Rust-dev@mozilla.org https://mail.mozilla.org/listinfo/rust-dev