3 ms·
Yes, it is an accurate description of Cell. RefCell is best thought of as a single-threaded RwLock. The Cell type doesn't allow you to get an &mut to the conte
by aliceryhl 6y ago
Yes, it is an accurate description of Cell. RefCell is best thought of as a single-threaded RwLock.
The Cell type doesn't allow you to get an &mut to the contents because a &mut requires exclusive access to the contents, which requires some sort of locking to do through an aliasing reference.
The Cell type also doesn't allow you to get an & to the contents, because a & requires the target to remain immutable for the duration of the reference.
For Copy types, Cell provides access through set/get, whereas for non-Copy types you can use swap/set.