Moved Strings in Rust

1. fn main() {
2. let s1: String = String::from("Rust");
3. let s2: String = s1;
4. }
  • The heap data from s1 is reused for s2.
  • When s1 goes out of scope, nothing happens (it has been moved from).

Before move to s2:

10.2. Moved Strings in Rust - 图1

After move to s2:

10.2. Moved Strings in Rust - 图2