fn closures in RBE

This commit is contained in:
Dan Buch 2023-10-01 06:01:54 -04:00
parent aa83db6f7a
commit 7e0aa3b86b
Signed by: meatballhat
GPG Key ID: A12F782281063434
2 changed files with 44 additions and 0 deletions

View File

@ -0,0 +1,36 @@
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();
}

View File

@ -0,0 +1,8 @@
fn main() {
let haystack = vec![1, 2, 3];
let contains = move |needle| haystack.contains(needle);
println!("{}", contains(&1));
println!("{}", contains(&4));
}