Moved Strings in Rust
fn main() { let s1: String = String::from("Rust"); let s2: String = s1; }
- The heap data from
s1is reused fors2. - When
s1goes out of scope, nothing happens (it has been moved from).
Before move to s2:
After move to s2:
fn main() { let s1: String = String::from("Rust"); let s2: String = s1; }
s1 is reused for s2.s1 goes out of scope, nothing happens (it has been moved from).Before move to s2:
After move to s2: