Step Into Labs

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.

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

Missions

  1. A function factory
  2. A closure that changes things
  3. Sort by any rule
  4. Compose