Move versus copy
Quick answer
Assignment does not always duplicate a resource. For a String, moving the value into a new binding transfers ownership. For a Copy type like i32, assignment duplicates the value and leaves the original usable.
Follow the owner
After let b = a; for a String, b owns the allocation; a is no longer usable unless reinitialized (and the binding permits it). A move does not require copying all bytes in the allocation. For a Copy integer, both a and b are independent values. The rules are about usable values, not the compiler's physical copying instructions.
fn main() { let a = 8; let mut b = a; b += 2; println!("{a} {b}");}Expected stdout (not executed):
8 10Changing the copy leaves the original integer unchanged.
fn main() { let a = String::from("ticket"); let b = a; println!("{b}");}Expected stdout (not executed):
ticketOnly b is usable as the owner after the move. Adding println!("{a}") would fail to compile.
Common mistake
Do not infer that a String assignment duplicates the buffer. Moving prevents two independent owners from freeing the same allocation.
Try it yourself
Draw owner a, then move it to b and label the old binding unusable. Compare with assignment of an integer.
Static examples for Rust 1.85.0, edition 2024. Run them locally in a disposable project; ByteMind execution support and these outputs have not been verified.
Check Your Understanding
Solidify your learning with the interactive assessment directly below this lesson.
Concept Quiz & Questions
Move versus copy — practice quiz
Choose one answer per question, then review the explanation.
After `let a=4; let b=a;`, can both bindings be read?
Does moving a String require copying its entire heap buffer?
After moving a mutable String binding, how can the original name become usable again?