use std::cell::{Ref, RefMut, RefCell};
use std::rc::Rc;
#[derive(Debug)]
pub struct RcVec<T>(pub Rc<RefCell<Vec<T>>>);
impl<T> RcVec<T> {
pub fn new(p: Vec<T>) -> RcVec<T> {
RcVec(Rc::new(RefCell::new(p)))
}
pub fn borrow(&self) -> Ref<Vec<T>> {
(*self.0).borrow()
}
pub fn borrow_mut(&self) -> RefMut<Vec<T>> {
(*self.0).borrow_mut()
}
}
impl<T> Clone for RcVec<T> {
fn clone(&self) -> RcVec<T> {
RcVec(self.0.clone())
}
}
impl<T> PartialEq for RcVec<T> {
fn eq(&self, other: &RcVec<T>) -> bool {
same_rc(&self.0, &other.0)
}
}
fn same_rc<T>(a: &Rc<T>, b: &Rc<T>) -> bool {
let a: *const T = &**a;
let b: *const T = &**b;
a == b
}