Move Semantics: Assignment

Overview

For heap-owning values like String, assignment moves ownership instead of copying heap data. After let s2 = s1;, s1 is no longer valid.

This prevents double-free bugs by ensuring only one owner is responsible for dropping the value.

Official Rust Book: Variables and Data Interacting with Move


Code example