Use the move keyword in a closure definition to force ownership transfer of captured variables.
Use the move keyword after the | in a closure definition to force it to take ownership of captured variables instead of borrowing them. This is required when passing closures to threads or when the captured data does not implement the Copy trait.
let s = String::from("hello");
let closure = move || println!("{s}");
closure();
The move keyword tells Rust to take full ownership of the variables a closure uses, rather than just borrowing them. This is like handing over the keys to your house to a guest instead of just letting them look through the window. You use it when you need the closure to keep the data alive after the original scope ends, such as when sending work to a new thread.