How to Use Closures for Callbacks in Rust

Define anonymous functions with `|args| body` syntax and pass them to functions expecting closure types like `FnOnce` to use them as callbacks.

Use closures as callbacks by defining an anonymous function with |args| body and passing it to a function expecting a closure type.

fn apply<F>(x: i32, f: F) -> i32 where F: FnOnce(i32) -> i32 {
    f(x)
}

fn main() {
    let add_two = |x| x + 2;
    let result = apply(5, add_two);
    println!("Result: {}", result);
}