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

Mutable string

  • push_str

  • If we initialize the varibale using String::from and make it mutable then we can change the string.

fn main() {
    let mut name = String::from("Foo");
    println!("{name}");

    name.push_str(" Bar");
    println!("{name}");
}
Foo
Foo Bar