小编cr7*_*gu3的帖子

如何在不复制的情况下将两个字符串连接到第三个字符串?

我是 Rust 新手,目前正在阅读《Rust 编程语言》一书。

我对这个例子很好奇:

fn main() {
    let s1 = String::from("Hello, ");
    let s2 = String::from("world!");
    let s3 = s1 + &s2; // note s1 has been moved here and can no longer be used
}
Run Code Online (Sandbox Code Playgroud)

是否有可能不仅拥有 的所有权s1,而且还拥有 的所有权s2,因此s2也变得无效,从而s1成为s3唯一仍然可用的变量?

string move concatenation ownership rust

3
推荐指数
1
解决办法
3162
查看次数

标签 统计

concatenation ×1

move ×1

ownership ×1

rust ×1

string ×1