1use derive_more::{Deref, DerefMut};
7pub use std::rc::Rc;
8
9#[cfg(feature = "debug-cell")]
10use debug_cell::RefCell;
11
12#[cfg(not(feature = "debug-cell"))]
13use std::cell::RefCell;
14
15#[derive(Deref, DerefMut)]
17pub struct RcMut<T>(Rc<RefCell<T>>);
18
19impl<T> RcMut<T> {
20 pub fn new(t: T) -> Self {
22 Self(Rc::new(RefCell::new(t)))
23 }
24}
25
26impl<T> Clone for RcMut<T> {
27 fn clone(&self) -> Self {
28 Self(self.0.clone())
29 }
30}
31
32impl<T> From<T> for RcMut<T> {
33 fn from(value: T) -> Self {
34 RcMut::new(value)
35 }
36}
37
38impl<T: std::fmt::Debug> std::fmt::Debug for RcMut<T> {
39 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
40 f.debug_tuple("RcMut").field(&self.0.borrow()).finish()
41 }
42}