Strings In Depth12 / 18
Up next

Grow a caller's String

// &mut String lets a function extend the caller's value
fn add_ext(s: &mut String) {
    s.push_str(".txt");
}

fn main() {
    let mut name = String::from("file");
    add_ext(&mut name);
    println!("{name}");
}
What you're solving

&mut String appends in place