3 ms·
I do not understand why it is &mut var Instead of mut &var Having two version of mut just doesn’t make sense to me. I love rust, but haven’t gotten nearly
by MR4D 4y ago
I do not understand why it is
&mut var
Instead of
mut &var
Having two version of mut just doesn’t make sense to me. I love rust, but haven’t gotten nearly enough time to use it, and little things like this use up more memory in my brain than it should for such a well thought out system.
- estebank 4y agoBoth are valid Rust. The former means "I don't own var, but I can change it", while the later means "I own a reference that I can change where it points, but I can't change the pointed value." An argument could be made that it shouldn't have been '&mut' and instead be something like '&exclusive'.
- pornel 4y ago`let mut` is completely unnecessary from perspective of the language's semantics (everything owned exclusively can be mutated safely), but exists because people really really like having an extra lint against accidental reassignment of a variable.