//! Custom cell impl use std::cell::UnsafeCell; use std::fmt; use std::rc::Rc; pub(crate) struct Cell { inner: Rc>, } impl Clone for Cell { fn clone(&self) -> Self { Self { inner: self.inner.clone(), } } } impl fmt::Debug for Cell { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { self.inner.fmt(f) } } impl Cell { pub fn new(inner: T) -> Self { Self { inner: Rc::new(UnsafeCell::new(inner)), } } pub fn get_mut(&mut self) -> &mut T { unsafe { &mut *self.inner.as_ref().get() } } }