1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
use std::rc::{ Rc, };
use std::cell::{ Cell, Ref, RefMut, RefCell, };


#[derive(Debug)]
pub struct RcRef<T> {
    inner: Rc<RefCell<T>>,
}

impl<T> Clone for RcRef<T> {
    fn clone(&self) -> Self {
        RcRef {
            inner: Rc::clone(&self.inner),
        }
    }
}

impl<T> RcRef<T> {
    pub fn new(val: T) -> Self {
        RcRef { inner: Rc::new(RefCell::new(val)) }
    }

    pub fn borrow(&self) -> Ref<T> {
        self.inner.borrow()
    }

    pub fn borrow_mut(&self) -> RefMut<T> {
        self.inner.borrow_mut()
    }
}