[Web Feed] Sometimes data structures need to mutate one or more of their fields even whe...

Feed Supplier <[email protected]>
Newsgroups alt.comp.programming
Organization Usenet.Farm
Message-ID <[email protected]>
..n they are declared immutable. This may sound surprising at fir



Sometimes data structures need to mutate one or more of their fields even when they are declared immutable. This may sound surprising at first, but you’ve probably relied on this behavior before, like when you clone a reference counted wrapper such as 


Rc


, or when you lock a 


Mutex


 However, in Rust, mutability is an all-or-nothing attribute: either a variable is declared as mutable and all of its fields are also mutable (if it is a 


struct


), or it’s declared immutable and so are all of its fields. How do we get selective field mutability? Something mysterious is afoot.




Link 1


Interior mutability in Rust: what, why, how?: https://ricardomartins.cc/2016/06/08/interior-mutability
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.