box-o-sand/rustbyexample/fn.d/closures.rs
2023-09-30 20:17:22 -04:00

13 lines
340 B
Rust

fn main() {
let outer_var = 42;
let closure_annotated = |i: i32| -> i32 { i + outer_var };
let closure_inferred = |i| i + outer_var;
println!("closure_annotated: {}", closure_annotated(1));
println!("closure_inferred: {}", closure_inferred(1));
let one = || 1;
println!("closure returning one: {}", one());
}