Borrow String when passing to a function



examples/ownership/string-function-borrow/src/main.rs
fn main() {
    let name = String::from("Foo Bar");
    println!("{name}");
    greet(&name);
    println!("{name}");
}

fn greet(text: &String) {
    println!("Greet: {}", *text); // explicit derefernce
    println!("Greet: {}", text);  // automatic dereference
    println!("Greet: {text}");
}

Foo Bar
Greet: Foo Bar
Greet: Foo Bar
Greet: Foo Bar
Foo Bar