expression
Move ownership into a worker
A move closure captures the owned data it needs, allowing the worker to outlive the caller’s local binding. A move closure can still contain borrowed references and is not automatically Send or static. Expected stdout (not executed): pen,book Common mistake: Assuming move extends the lifetime of a borrowed referent.
Formal Syntax & Structure
rust syntaxrust
thread::spawn(move || use_value(value))Working Example
Example Snippetrust
fn main() { let labels = vec![String::from("pen"), String::from("book")]; let h = std::thread::spawn(move || labels.join(",")); println!("{}", h.join().unwrap());}