How to use the move keyword with closures

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();