diff options
| author | bors <bors@rust-lang.org> | 2013-11-24 08:42:35 -0800 |
|---|---|---|
| committer | bors <bors@rust-lang.org> | 2013-11-24 08:42:35 -0800 |
| commit | 01b53817033ba3a3ec01685d30e4a8e7ce14ba0c (patch) | |
| tree | 3c8cec9365f78cc8ff34db824845784cc5dde4e5 /src/libstd | |
| parent | ae91b81a6f7cba76d94ce00ef8155b9550344929 (diff) | |
| parent | fdac9e470cd87429b6aefc6e02772163a8d41fc8 (diff) | |
| download | rust-01b53817033ba3a3ec01685d30e4a8e7ce14ba0c.tar.gz rust-01b53817033ba3a3ec01685d30e4a8e7ce14ba0c.zip | |
auto merge of #10634 : LeoTestard/rust/rc-eq, r=cmr
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/rc.rs | 55 |
1 files changed, 55 insertions, 0 deletions
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<T> { value: T, @@ -80,6 +81,60 @@ impl<T> Rc<T> { 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<T>) -> bool { + self.ptr == other.ptr + } +} + +impl<T: Eq> Eq for Rc<T> { + #[inline] + fn eq(&self, other: &Rc<T>) -> bool { + unsafe { (*self.ptr).value == (*other.ptr).value } + } + + #[inline] + fn ne(&self, other: &Rc<T>) -> bool { + unsafe { (*self.ptr).value != (*other.ptr).value } + } +} + +impl<T: TotalEq> TotalEq for Rc<T> { + #[inline] + fn equals(&self, other: &Rc<T>) -> bool { + unsafe { (*self.ptr).value.equals(&(*other.ptr).value) } + } +} + +impl<T: Ord> Ord for Rc<T> { + #[inline] + fn lt(&self, other: &Rc<T>) -> bool { + unsafe { (*self.ptr).value < (*other.ptr).value } + } + + #[inline] + fn le(&self, other: &Rc<T>) -> bool { + unsafe { (*self.ptr).value <= (*other.ptr).value } + } + + #[inline] + fn ge(&self, other: &Rc<T>) -> bool { + unsafe { (*self.ptr).value >= (*other.ptr).value } + } + + #[inline] + fn gt(&self, other: &Rc<T>) -> bool { + unsafe { (*self.ptr).value > (*other.ptr).value } + } +} + +impl<T: TotalOrd> TotalOrd for Rc<T> { + #[inline] + fn cmp(&self, other: &Rc<T>) -> Ordering { + unsafe { (*self.ptr).value.cmp(&(*other.ptr).value) } + } } impl<T> Clone for Rc<T> { |
