2 ms·
Rust's iterators are single-use streams of items, and nothing more. A Rust iterator can be fully implemented by a closure that either returns the next element
by pornel 2y ago
Rust's iterators are single-use streams of items, and nothing more.
A Rust iterator can be fully implemented by a closure that either returns the next element or signals it's done. This minimalist interface composes well, especially that it always uses single ownership, so there's always only one copy of the state accessed only from one place.
They can't describe collections. They don't remember their beginning. They don't need to know their end until they reach it. They can't be sorted. They don't need to support splitting or iterating in reverse.