fn add_one(x: i32) -> i32 { x + 1 } /// A function with a function pointer argument fn do_twice(f: fn(i32) -> i32, arg: i32) -> i32 { f(arg) + f(arg) } #[derive(Debug)] enum Status { Value(u32), Stop, } fn returns_closure() -> Box i32> { Box::new(|x| x + 1) } fn main() { let answer = do_twice(add_one, 5); println!("The answer is: {}", answer); // Tuple Structs set up via function pointers let list_of_statuses: Vec = (0u32..20) .map(Status::Value) .collect(); println!("List of statuses: {:?}", list_of_statuses); let increment = returns_closure(); let x = 5; let y = increment(x); println!("The returned closure returns: {}", y); }