What is the difference between move and copy

The move keyword transfers ownership of variables to a closure, while Copy types are duplicated automatically without ownership transfer.

The move keyword forces a closure to take ownership of captured variables, whereas copy (via the Copy trait) duplicates simple types like integers without transferring ownership. Use move when you need a closure to own data that outlives its scope, such as when passing it to another thread.

let data = String::from("hello");
let closure = move || println!("{}", data); // Takes ownership of data
let x = 5;
let closure2 = || println!("{}", x); // Copies x because i32 implements Copy