Exerpad
🔥0
0 XP
Lv.1 Beginner
Log In

Fix the String

This code tries to push more text onto a string, but it doesn't compile! The variable needs to be a String (not a &str) and it needs to be mutable.

Fix the code so it prints:

text
Hello, world!

Hint: Change the string literal into a String using String::from() and don't forget to make it mut!

rust
fn main() {
let greeting = "Hello";
greeting.push_str(", world!");
println!("{}", greeting);
}