use std::cell::{Ref, RefCell, RefMut}; use std::rc::Rc; //a Rrc //tp Rrc #[derive(Debug)] pub struct Rrc(Rc>); impl From for Rrc { fn from(data: T) -> Self { Self(Rc::new(RefCell::new(data))) } } impl Clone for Rrc { fn clone(&self) -> Self { Self(self.0.clone()) } } impl Rrc { pub fn borrow(&self) -> Ref { self.0.borrow() } pub fn borrow_mut(&self) -> RefMut { self.0.borrow_mut() } } impl std::default::Default for Rrc where T: Default, { fn default() -> Self { T::default().into() } } impl std::ops::Deref for Rrc { type Target = RefCell; fn deref(&self) -> &RefCell { &self.0 } }