Exerpad
🔥0
0 XP
Lv.1 Beginner
Log In

Fix the Borrow

This code tries to modify a borrowed String, but the borrow isn't mutable! Fix it so the program prints:

text
Hello, World!

Hint: You need &mut instead of &, and the variable must be declared with mut.

rust
fn add_world(text: &String) {
text.push_str(", World!");
}

fn main() {
let greeting = String::from("Hello");
add_world(&greeting);
println!("{}", greeting);
}