Non-working example on how to fix ownership

This commit is contained in:
Fabian Schmidt 2024-02-20 11:41:21 +01:00
parent 14e7c08152
commit 11597fa330
3 changed files with 31 additions and 3 deletions

7
Cargo.lock generated Normal file
View File

@ -0,0 +1,7 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
version = 3
[[package]]
name = "rcrefcell"
version = "0.1.0"

24
src/bin/notworking.rs Normal file
View File

@ -0,0 +1,24 @@
fn c<F: FnOnce() + 'static>(f: F) {
f();
}
fn main() {
let v = vec![1, 2, 3];
c({
let mut v = v.clone();
move || {
println!("inner 1: {:?}", v);
v.push(4);
}
});
c({
let mut v = v.clone();
move || {
println!("inner 2: {:?}", v);
v.push(5);
}
});
println!("outer: {:?}", v);
}

View File

@ -1,3 +0,0 @@
fn main() {
println!("Hello, world!");
}