When you assign a heap-allocated String to another variable (let s2 = s1;), Rust moves ownership to s2 and invalidates s1—preventing a "double free" bug! Simple stack-only types (i32, bool, f64, char) implement the Copy trait and are copied automatically instead.
ADVERTISEMENT