Re:Show HN: Bolt: A research language with finer-grained con...
by aliceryhl on Sunday May 10, 2020 @11:15AM
(#23133250)
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.
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.