Closures and Capture Semantics

Updated

October 31, 2026

Closures and Capture Semantics

Closures are anonymous functions that can capture environment variables: - Fn: Borrows values from the environment immutably. - FnMut: Borrows values mutably. - FnOnce: Takes ownership and consumes captured values.

fn main() {
    let factor = 3;
    let multiply = |x| x * factor;
    println!("Result: {}", multiply(10));
}