2 ms·
> Diverging from TFA, local bindings are immutable (by default), however there have been rumblings about dropping this, and essentially always making them mutab
by cesarb 5y ago
> Diverging from TFA, local bindings are immutable (by default), however there have been rumblings about dropping this, and essentially always making them mutable because the signal is pretty low.
I hope that never happens; one of the best things in Rust is that it's easier (less typing) to make things non-mutable, which in the case of local bindings tends to encourage a more functional programming style (for instance, it encourages "let x = if foo { bar } else { baz };" instead of "let mut x; if foo { x = bar; } else { x = baz; }").
- creata 5y agoAgreed, but for that particular example, the compiler is smart enough to see that x is assigned exactly once, so you can have x be immutable in both examples. https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=504978eb7a3de80c22d00fd402816660 https://play.rust-lang.org/?version=stable&mode=debug&editio...