DEV Community

Discussion on: Async, refactoring and fewer bugs: Rust block expressions to the rescue

Collapse
 
calebsander profile image
Caleb Sander

Nice discussion! I would point out that you can also stop a variable from being mut by shadowing its binding:

// `values` is mutable so that we can add to it
let mut values = vec![];
for i in 1..10 {
  values.extend(vec![i; i]);
}
let values = values;
// `values` is no longer mutable
Enter fullscreen mode Exit fullscreen mode

I agree that using a block seems more elegant, but like using drop(), this avoids a level of indentation.