#[derive(Debug)]
struct Position {
x: i32,
y: i32,
}
fn main() {
let pos = Position { x: 4, y: 5 };
let foo1 = move || {
println!("{:?}", pos);
};
let foo2 = move || {
println!("{:?}", pos);
};
foo1();
foo2();
}
I got the error message:
error[E0382]: use of moved value: `pos`
--> src/main.rs:14:16
|
8 | let pos = Position { x: 4, y: 5 };
| --- move occurs because `pos` has type `Position`, which does not implement the `Copy` trait
9 |
10 | let foo1 = move || {
| ------- value moved into closure here
11 | println!("{:?}", pos);
| --- variable moved due to use in closure
...
14 | let foo2 = move || {
| ^^^^^^^ value used here after move
15 | println!("{:?}", pos);
| --- use occurs due to use in closure