A couple of ideas were outlined in this reddit comment.
1: Implementing the API for Cell<Rc<T>> and Cell<Vec<T>>: requires a lot of unsafe.
There might be a way to provide mutable access to the contents of Cell via Cell::with_mut(|mut_ref| {...}) and have the compiler prove that the closure cannot reach the Cell::with_mut entry point, but it's not something we can express right now.
2: Turning &mut T into multiple aliases with Cell semantics:
impl<T: Copy> Cell<T> {
fn from_mut(x: &mut T) -> &Cell<T> {
unsafe { mem::transmute(x) }
}
}
I am not certain this is UB-free, but if it isn't, I still expect @glaebhoerl's CellRef<'a, T> suggestion to work.
cc @nikomatsakis
A couple of ideas were outlined in this reddit comment.
1: Implementing the API for
Cell<Rc<T>>andCell<Vec<T>>: requires a lot ofunsafe.There might be a way to provide mutable access to the contents of
CellviaCell::with_mut(|mut_ref| {...})and have the compiler prove that the closure cannot reach theCell::with_mutentry point, but it's not something we can express right now.2: Turning
&mut Tinto multiple aliases withCellsemantics:I am not certain this is UB-free, but if it isn't, I still expect @glaebhoerl's
CellRef<'a, T>suggestion to work.cc @nikomatsakis