t_wの輪郭

Feedlyでフォローするボタン
+演算子による文字列の結合+演算子format&str

&str&strの結合

+演算子では不可能。formatを使おう。

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!!!
  |              ~~~~~~~~~~~~~
あれ