Re:Copying data is wasteful, mutating data is dangerous
by shpongled on Thursday January 09, 2020 @12:37PM
(#22003408)
I think the easier way to think about Rust's interior mutability is via an example: (Cell is a mechanism for interior mutability)
To mutate field `b` on `T`, we need a mutable object or reference. However, we can mutate field `a` on `S` via an immutable reference. Typically this is used to encapsulate some kind of interior state that isn't visible outside of the struct's methods, and helps in certain situations where using a mutable reference might cause some hair pulling due to the borrow checker
[ Parent
| on HN ]
There are no comments on this comment yet.