The below code doesn't work because the argument to thread::spawn
requires that some
is borrowed for 'static
, I get it:
fn main() {
let some = "Some".to_string();
let apple = Arc::new(&some);
for _ in 0..10 {
let apple = apple.clone();
thread::spawn(move || {
println!("{:?}", apple);
});
}
}
But how come the following works? Since String
is not Copy
, how come this doesn't also cause the borrowed value to not live long enough? Is the String
becoming static to adjust for the thread code?
fn main() {
let some = "Some".to_string();
let apple = Arc::new(some);
for _ in 0..10 {
let apple = apple.clone();
thread::spawn(move || {
println!("{:?}", apple);
});
}
}