box-o-sand/rustbyexample/fn.d/closures.rs

13 lines
340 B
Rust
Raw Normal View History

2023-10-01 00:17:22 +00:00
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());
}