Having read the first chapters of The Book, I’m still somewhat confused about the meaning of mut when applied to a variable, like in:
let mut x = 5;
let mut v = Vec::new();
My current understanding is, that mut has two effects:
- It allows to assign another value to the variable later on.
- It allows to modify the object that the variable refers to later on.
If I want to do either of this two things, I have to use mut.
I am wondering if this understanding is correct, because actually this two things have quite different semantics in my opinion. Are they really covered by one keyword, and what is the rationale behind this ?