in this part a bit confusing about what happening my code isn't same with the doc example is there have some improvement on ownership architecture in rust can someone explain me or give some reference link?
1 Like
the code you have and the code in listing 16-5 are the same, and they are both correct code that will not generate error. notice what the book actualy says
this is about listing 16-4 :
use std::thread;
fn main() {
let v = vec![1, 2, 3];
let handle = thread::spawn(|| {
println!("Here's a vector: {v:?}");
});
drop(v); // oh no!
handle.join().unwrap();
}
what they explain is that this code, that has the drop, cannot be fixed with move, and then show the error you would get if you tried to add move to it.
so the error they show can be triggered by writing
use std::thread;
fn main() {
let v = vec![1, 2, 3];
let handle = thread::spawn(move || {
println!("Here's a vector: {v:?}");
});
drop(v); // oh no!
handle.join().unwrap();
}
ahh i see sorry not read carefully on it haha

