Iterators

Iterators in Rust provide a way to lazily evaluate a sequence of values. All iterators implement the trait, which has one associated type, , and one method,  , with the following signature:

While the iterator can still produce values,  should return   with each value. Once the iterator is finished, it returns  and any further calls to   will probably panic.

Iterators are analogous to the  monad in Haskell, and iterators in many other languages like Python.

Fused iterators
In Rust it can be useful to have an iterator that will continue to return  after it has returned it once instead of panicking. The trait guarantees this, and it is implemented by all iterators that have this behaviour. Additionally, any iterator can become fused by calling Iterator::fuse on it, which for already-fused iterators is a no-op and for unfused iterators will keep track of whether the iterator has ended or not.