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

Pass ownership of String to function

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

    greet(name);

    // We cannot use name any more as it was moved
    //println!("{name}"); // borrow of moved value: `name`
    //greet(name);        // use of moved value: `name`
}

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