diff --git a/src/libstd/rc.rs b/src/libstd/rc.rs index 242533773d7..1b1546e57a3 100644 --- a/src/libstd/rc.rs +++ b/src/libstd/rc.rs @@ -22,6 +22,7 @@ use ops::Drop; use kinds::{Freeze, Send}; use clone::{Clone, DeepClone}; use cell::RefCell; +use cmp::{Eq, TotalEq, Ord, TotalOrd, Ordering}; struct RcBox { value: T, @@ -80,6 +81,60 @@ impl Rc { pub fn borrow<'r>(&'r self) -> &'r T { unsafe { &(*self.ptr).value } } + + /// Determine if two reference-counted pointers point to the same object + #[inline] + pub fn ptr_eq(&self, other: &Rc) -> bool { + self.ptr == other.ptr + } +} + +impl Eq for Rc { + #[inline] + fn eq(&self, other: &Rc) -> bool { + unsafe { (*self.ptr).value == (*other.ptr).value } + } + + #[inline] + fn ne(&self, other: &Rc) -> bool { + unsafe { (*self.ptr).value != (*other.ptr).value } + } +} + +impl TotalEq for Rc { + #[inline] + fn equals(&self, other: &Rc) -> bool { + unsafe { (*self.ptr).value.equals(&(*other.ptr).value) } + } +} + +impl Ord for Rc { + #[inline] + fn lt(&self, other: &Rc) -> bool { + unsafe { (*self.ptr).value < (*other.ptr).value } + } + + #[inline] + fn le(&self, other: &Rc) -> bool { + unsafe { (*self.ptr).value <= (*other.ptr).value } + } + + #[inline] + fn ge(&self, other: &Rc) -> bool { + unsafe { (*self.ptr).value >= (*other.ptr).value } + } + + #[inline] + fn gt(&self, other: &Rc) -> bool { + unsafe { (*self.ptr).value > (*other.ptr).value } + } +} + +impl TotalOrd for Rc { + #[inline] + fn cmp(&self, other: &Rc) -> Ordering { + unsafe { (*self.ptr).value.cmp(&(*other.ptr).value) } + } } impl Clone for Rc {