Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Concatenation String with String

fn main() {
    let string1 = String::from("Apple");
    let string2 = String::from("Banana");

    //let text = string1 + string2; // mismatched types
    let text = string1 + &string2; // we move strin1 and then copy the content of string2
    println!("{}", text);
    println!("{}", string2);
    // println!("{}", string1);   // error[E0382]: borrow of moved value: `string1`
}
AppleBanana
Banana