5 ms·
`Rc` freezes the value as long as it's shared unless you use interior mutability. It's fine when you want to share immutable data, but if you ever need to mutat
by a_rustacean 5y ago
`Rc` freezes the value as long as it's shared unless you use interior mutability. It's fine when you want to share immutable data, but if you ever need to mutate its contents you will have to deal with awkward cases and situations, and at runtime!
Wrapping everything in `Rc` is not a good default strategy. Instead figure out an architecture that works well with the borrow checker! This normally means thinking hard about your data structures and the ownership model of your application.
I love Rust precisely because of this. You can leverage the compiler to drive your development and design. If it's hard, then it's probably wrong!
- hailwren 5y agoAre there any good resources for design patterns in Rust? I've gone through Rust by example and am writing mid-size rust programs now but would love to check my work against the experts.
- ssokolow 5y agoThere's The Unofficial Rust Design Patterns Book... https://rust-unofficial.github.io/patterns/ https://rust-unofficial.github.io/patterns/ (More generally, there's the Little Book of Rust Books to find things like that: https://lborb.github.io/book/ https://lborb.github.io/book/ ) ...and someone asked about good code to learn from on Reddit a day or two ago and was advised to read basically any code by dtolnay or burntsushi, two of the big wizards who feel like they've written half the Rust ecosystem at times.
- mgaunard 5y agoRust also just enforces good C++ practices, so you could just get yourself familiar with the 40 years history of C++.
- dan00 5y ago> I love Rust precisely because of this. You can leverage the compiler to drive your development and design. If it's hard, then it's probably wrong! Yes, I had the same experience writing code in Rust and Haskell. If the design works nicely with the language, then also the design is better, more modular, simpler dependencies and easier to understand and extend.
- scotty79 5y agoI'll stick to my Rc's, thanks. Limiting yourself to immutable data is a good idea anyways for all scenarios where it is possible.
- ReleaseCandidat 5y ago> If it's hard, then it's probably wrong! Trees and graphs?
- ohgodplsno 5y agoThe borrow checker gets to actively tell you that your family tree has some inbreeding!
- drran 5y agoWhat the problem with trees? They are trees, not cyclic graphs.