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 str with str

  • In the example we have two strings hard-coded in the binary of our executable.
fn main() {
    let str1 = "Hello";
    let str2 = "World";

    // let text = str1 + str2; // cannot add `&str` to `&str`
    let text = str1.to_owned() + " " + str2;
    println!("{}", text);
}
Hello World