|
|
|
|
|
by Manishearth
3803 days ago
|
|
... It takes some getting used to. If you've programmed in a functional way before, try shifting perspective in that direction a bit. Rust isn't pure functional, and pure functional programming won't work well in Rust, but the style of programming has some similar parts. It's a really bad idea to try and write stuff in a "C++ way" with tons of mutation, Rust encourages a rather different discipline in handling data which is at odds with the regular C++ style of programming. But this takes time to pick up. Once you've programmed with it for a while it feels pretty natural, though, especially since it's very easy to reason about data in this model. Here's why Rust has this model: http://manishearth.github.io/blog/2015/05/17/the-problem-wit... As geofft mentioned below, you can get mutable references to multiple fields if you want. In more complex situations, use Cell<T> (for copyable types, this is zero cost though it can prevent some optimizations) or RefCell<T> (this works for any type, but has a slight cost) for more fine-grained mutability control. You shouldn't need these often, but they exist |
|