Rust 是否应该在使用 push_str() 将一个新字符串连接到另一个字符串时给出一个错误?

问题描述 投票:0回答:1

想要连接一个字符串。这不应该引起某种恐慌或编译错误吗?

let mut s=String::from("abc").push_str("x");
println!("{:?}",s);  // Prints ()

但这行得通:

let mut s=String::from("abc");
s.push_str("x");  
println!("{:?}",s);  // Prints "abcx"
string rust concatenation
1个回答
0
投票

push_str
不返回输入字符串;它没有返回值。没有返回值的方法隐式返回
()
.

pub fn push_str(&mut self, string: &str)
最新问题
© www.soinside.com 2019 - 2024. All rights reserved.