let hello:String = String::from("hello");
let world:String = String::from("world");
let hello_world = format!("{} {}", hello, world);
println!("{}", hello_world); //hello world
let hello:String = String::from("hello");
let world:&str = "world";
let hello_world = format!("{} {}", hello, world);
println!("{}", hello_world); //hello world
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!!!
| ~~~~~~~~~~~~~