Closures & Iterators
Closures and iterators are Rust’s core functional-style tools for local behavior customization and lazy sequence processing with low-level performance.
Concepts
- Closures
- Closure Type Inference
- Capturing the Environment
- Fn, FnMut, FnOnce
- move Closures
- Iterators
- The Iterator Trait
- Iterator Adapters
- Consuming Adapters
- Lazy Evaluation
- Zero-Cost Abstractions
Patterns
Antipatterns
Related Existing Notes
Function Pointers · Returning Closures · Boxed Closure Returns · Unnecessary Collect · While and For Loops · Needless Clone · Ownership · Borrowing
Sources
- The Rust Programming Language, ch. 13 “Functional Language Features: Iterators and Closures” - the-book, https://doc.rust-lang.org/book/ch13-00-functional-features.html
- The Rust Programming Language, ch. 13.1 “Closures” - the-book, https://doc.rust-lang.org/book/ch13-01-closures.html
- The Rust Programming Language, ch. 13.2 “Processing a Series of Items with Iterators” - the-book, https://doc.rust-lang.org/book/ch13-02-iterators.html
- The Rust Programming Language, ch. 13.4 “Comparing Performance: Loops vs. Iterators” - the-book, https://doc.rust-lang.org/book/ch13-04-performance.html
