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

37 lines
544 B
Rust
Raw Normal View History

2023-10-01 10:01:54 +00:00
fn main() {
use std::mem;
let color = String::from("green");
let print = || println!("`color`: {}", color);
print();
let _reborrow = &color;
print();
let _color_moved = color;
let mut count = 0;
let mut inc = || {
count += 1;
println!("`count`: {}", count);
};
inc();
inc();
let _count_reborrowed = &mut count;
let movable = Box::new(3);
let consume = || {
println!("`movable`: {:?}", movable);
mem::drop(movable);
};
consume();
}