Rust Tutorial #12: Closures and Iterators
In the previous tutorial, we learned lifetimes. Now we learn two features that make Rust code clean and expressive: closures and iterators. Closures are anonymous functions you can store in variables and pass to other functions. Iterators let you process collections step by step. Together, they replace most loops with short, readable code. What Is a Closure? A closure is a function without a name. It can capture variables from its environment: ...