The Iterator trait
Anything that implements `Iterator` exposes a stream of values. The trait has many provided methods — `map`, `filter`, `fold`, `collect` — that operate lazily by default.
For deeper background, see the canonical Rust learning roadmap for the broader context behind this section.
Closures
Closures are anonymous functions that can capture their environment. Their type is inferred, and they can implement `Fn`, `FnMut`, or `FnOnce` depending on how they capture.
Lazy evaluation
Iterator chains do nothing until a terminal operation like `collect`, `for`, `sum`, or `count` consumes them. This means long chains have very little runtime overhead.
Performance
Iterators in Rust optimise to the same machine code as hand-written loops. There is no abstraction penalty — you get the higher-level expressiveness for free.