What problem does it solve?
Canonical reference for iterator and closure idioms in Rust. Detects and fixes:
C-style index loops where an iterator adapter fits, unused lazy iterators (map/filter
with no terminal), needless intermediate Vec from chained collect+loop, .clone() inside
.map() to dodge a borrow, unwrap() inside map/filter instead of collect::<Result<,>>(),
oversized move closures capturing large structs by value, and FnOnce/FnMut/Fn bound
mismatches (E0525). Covers: iterator laziness, Iterator trait + next, consuming vs
non-consuming adapters (map, filter, fold, collect, zip, enumerate), turbofish on
collect(), collecting into Result, iter vs iter_mut vs into_iter, Fn/FnMut/FnOnce
traits and when each is required, move closures for spawned tasks and 'static bounds,
borrow-not-clone discipline, and zero-cost abstraction.
Core Features & Use Cases
- Replace C-style index loops with iterator adapters
- Use correct iterator ownership (iter/iter_mut/into_iter) and consuming adapters
- Detect and avoid common pitfalls (unwrap/expect inside closures, .clone() in map, lazy iterators)
Quick Start
Refactor target loops and closures into idiomatic Rust iterator chains and closures.