0

Why does reassigning a mutable String results in compile error? Shouldn't mut allow mutating string?

fn main() {
    let mut guess = String::from("foo\n");
    guess = guess.trim();
    println!("Input: {}", guess);
}

Gives

9 |     guess = guess.trim();
  |             ^^^^^^^^^^^^- help: try using a conversion method: `.to_string()`
  |             |
  |             expected struct `String`, found `&str`
phoxd
  • 1,546
  • 3
  • 12
  • 26

0 Answers0