A move transfers ownership of a value instead of copying or cloning it. It can happen when a value is assigned, passed to a function, captured by a closure, or returned; values passed by value move when their type does not implement Copy. section 4.2.1
Use the ownership transfer deliberately:
- Pass by value when the callee needs ownership, such as when it will return the value or incorporate it into a new result. References usually suit temporary access; mutable references allow mutation without transferring ownership. section 4.2.3
- A move closure captures values by ownership. If it consumes a captured value, it implements FnOnce and cannot be called again after that value has been consumed. The move keyword is optional when Rust infers the same capture, but makes intent explicit. section 3.2.2
Return a moved value
A function can take ownership of a String, reverse it, and return a new String. Returning multiple results can transfer them together in a tuple. section 4.2.1
Listing 3.3 Closure with move
let consumable = String::from("cookie");
let consumer = move || consumable;
consumer();
// consumer(); error!
A closure takes ownership of a String and returns it; calling the consumer again is invalid because the value has already been consumed. section 3.2.2




