Moved Strings in Rust
fn main() {
let s1: String = String::from("Rust");
let s2: String = s1;
}
- The heap data from
s1
is reused fors2
. - When
s1
goes 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
:
本文档使用 BookStack 构建