Step Into Rust · Lesson 9 · Robust Rust
Closures: Functions That Capture
Anonymous functions that remember their surroundings: Fn, FnMut and FnOnce, move closures, and functions that take or return them.
- ~30 minreading and coding
- 4missions
- membersaccess
- Rustlanguage
Part of Step Into Rust. The full lesson, its missions and the real compiler and debugger are in the course. Try a free lesson first to see how it works.
A closure is an anonymous function written where you need it. You have already passed some to iterator methods:
In this lesson
- A function you can write inline
- Three ways to capture, three traits
- move closures
- Taking closures as parameters
- Returning closures
Missions
- A function factory
- A closure that changes things
- Sort by any rule
- Compose