A mutable variable is declared and initialized with the keyword mut, but when it's used in the next line of code, the keyword mut must be repeated;
let mut guess = String::new();
io::stdin()
.read_line(&mut guess)
.expect("Failed to read line");
My expectation is that once a variable is declared and initialized as mutable, it remains to be so. Is this a syntactic sugar or is there a specific reason for this?
I would expect the above code to be like this:
let mut guess = String::new();
io::stdin()
.read_line(&guess)
.expect("Failed to read line");
Note that I have omitted the mut keyword in the call to read_line.