Strings In Depth8 / 18
Up next

Take &str, accept both

// prefer &str params: they accept literals AND &String
fn shout(s: &str) -> String {
    s.to_uppercase()
}

fn main() {
    let owned = String::from("hi");
    // &String coerces to &str automatically
    println!("{}", shout(&owned));
    println!("{}", shout("there"));
}
What you're solving

deref coercion passes &String as &str