4 ms·
I've seen people find Rust difficult for three reasons: * &mut is an "infectious leaky abstraction". It places restrictions on the caller, specifically that no
by verdagon 4y ago
I've seen people find Rust difficult for three reasons:
* &mut is an "infectious leaky abstraction". It places restrictions on the caller, specifically that nobody can have a reference to that data. This disqualifies many useful patterns such as backreferences, observers, dependency references, graphs, delegates, and certain kinds of RAII.
* Rust tends to lean very heavily on the type system to surface as much detail as possible into e.g. function signatures, but can conflict when the signature is set in stone, such as when implementing a trait or exposing a public function. It also does this with non-type-system denizens, such as async/await.
* A reluctance to fall back to Rc and RefCell. Programs often have inherent shared mutability, and the alternatives are often more complex.
These restrictions make the borrow checker incompatible with code we'd naturally write in any other language. Luckily, with enough practice, it can "click" and one can get used to the architectures that are compatible with its restrictions.
The tradeoff isn't ideal for some use cases. For others, it can be a great fit.