use std::cell::{Ref, RefMut, RefCell};
use std::rc::Rc;
use {
WriteBuffer,
WriteOptions,
};
use super::Path;
#[derive(Debug)]
pub struct RcPath(pub Rc<RefCell<Path>>);
impl RcPath {
pub fn new(p: Path) -> RcPath {
RcPath(Rc::new(RefCell::new(p)))
}
pub fn borrow(&self) -> Ref<Path> {
(*self.0).borrow()
}
pub fn borrow_mut(&self) -> RefMut<Path> {
(*self.0).borrow_mut()
}
}
impl Clone for RcPath {
fn clone(&self) -> RcPath {
RcPath(self.0.clone())
}
}
impl PartialEq for RcPath {
fn eq(&self, other: &RcPath) -> 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
}
impl WriteBuffer for RcPath {
fn write_buf_opt(&self, opt: &WriteOptions, buf: &mut Vec<u8>) {
(*self.0).borrow().write_buf_opt(opt, buf)
}
}