3 ms·
You can't mutate variables in rust without declaring mut
by UK-Al05 8y ago
You can't mutate variables in rust without declaring mut
- StreamBright 8y agoBut how do you know just by reading that code? It would not be obvious to me at all.
- goto11 8y agoYou mean if you don't know the language?
- StreamBright 8y agoI guess I just need to learn Rust. I wouldn't write a style of code where I have 3 lets after an other and using the same variable name.
- bryal 8y agoI think it's quite fine to assume the reader knows enough rust to know the difference between mutable and immutable variables.
- empath75 8y agolet foo = bar; let foo = bat; is shadowing let foo = bar; foo = bat; is a compilation-time error because foo isn't mutable. let mut foo = bar; foo = bat; is reassignment. in working code, either foo is declared as mutable or it's not, and it's pretty obvious from the code what's happening.
- StreamBright 8y agoI guess. I would just never write code like that.
- deleted 8y ago[deleted]
- hamaluik 8y agoI guess if you don't know rust you might not? But one of the first things you learn about rust is the `mut` keyword.
- eximius 8y ago`let` rebinds. If there isn't a `let`, it's mutation.