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

Borrow &str when passing String to a function

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

fn greet(text: &str) {
    println!("Greet: {text}");
}
Foo Bar
Greet: Foo Bar
Foo Bar