How to return a closure from a function

Return a closure from a Rust function by defining the return type as impl Fn and using move to capture environment variables.

Define a function that returns a closure type impl Fn and use the move keyword if the closure needs to own captured variables.

fn make_adder(x: i32) -> impl Fn(i32) -> i32 {
    move |y| x + y
}

fn main() {
    let adder = make_adder(10);
    println!("{}", adder(5)); // Prints 15
}