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

Rust function to change string

fn main() {
    let mut text = String::from("Foo");
    println!("Main: {text}");
    display(&text);
    change(&mut text);
    println!("Main: {text}");
    display(&text);
}

fn display(txt: &str) {
    println!("Display: {txt}")
}

fn change(txt: &mut String) {
    //*txt = String::from("Bar");
    txt.push_str(" Bar");
}
Main: Foo
Display: Foo
Main: Foo Bar
Display: Foo Bar