News for hackers. Stuff that matters.
Re:Show HN: Bolt: A research language with finer-grained con... by saagarjha on Sunday May 10, 2020 @03:19AM (#23130914)
> you have an &Cell<String> (aliasing mutable reference to owned string)

Is this really an accurate description of what this is? This sounds a lot more like RefCell to me (what would you call that?). Cell seems more like “an aliasing container that holds a particular owned value”, which might sound like gibberish to someone familiar to Rust but makes it clear to me at least that it really doesn’t actually let you grab a reference to the thing inside of it and get away with it.

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.

Re:Show HN: Bolt: A research language with finer-grained con... by comex on Sunday May 10, 2020 @03:34AM (#23130959)
Well, I'm thinking from a sort of low-level "what assembly does it generate" perspective, and from that perspective you can treat `&Cell<T>` almost as its own type of reference, as if it were `&cell T` or something – in other words, a way to represent an aliasing mutable pointer in Rust's type system. After all, you can create a 'Cell reference' to any object, without actually creating a Cell in the first place, by using `Cell::from_mut` to go from `&mut T` to `&Cell<T>`. And all the read/write operations on Cell compile to the same assembly as directly reading or writing a pointer; it's just that the set of operations available is restricted for safety.

From that low-level perspective, `&RefCell<String>` is something silly like "a reference to a structure containing a string and also a borrow count". ;p