+演算子による&strと&strの結合(無理)
2022/2/19 15:25:00
&str
と&str
の結合
fn main() {
let s1:&str = "Hello, ";
let s2:&str = "world!";
let s3 = s1 + &s2; // error!!!
println!("{}", s3);
}
error[E0369]: cannot add `&&str` to `&str`
--> src\main.rs:4:17
|
4 | let s3 = s1 + &s2; // error!!!
| -- ^ --- &&str
| | |
| | `+` cannot be used to concatenate two `&str` strings
| &str
|
help: `to_owned()` can be used to create an owned `String` from a string reference. String concatenation appends the string on the right to the string on the left and may require reallocation. This requires ownership of the string on the left
|
4 | let s3 = s1.to_owned() + &s2; // error!!!
| ~~~~~~~~~~~~~