Back to course

Closures: Anonymous Functions

Rust for Systems & Web3 Security

Functional Rust

Closures are anonymous functions you can save in a variable or pass to other functions. They can capture variables from the scope in which they’re defined.

rust let add_one = |x: i32| x + 1; let result = add_one(5);

Closures are heavily used with iterators and in asynchronous programming.