about summary refs log tree commit diff
diff options
context:
space:
mode:
authorGeordon Worley <vadixidav@gmail.com>2016-05-01 04:07:47 -0400
committerGeordon Worley <vadixidav@gmail.com>2016-05-01 04:07:47 -0400
commit666dd57c807a97177125cbf7f2365837d2c1e8eb (patch)
treeb537870481bfe89407f873d83db0180b61b5c4d2
parent2a815a26c8ce70e1aede585827c020d9775a8faf (diff)
downloadrust-666dd57c807a97177125cbf7f2365837d2c1e8eb.tar.gz
rust-666dd57c807a97177125cbf7f2365837d2c1e8eb.zip
fix implementation of Ord for Cell<T> and RefCell<T> where T: Ord
-rw-r--r--src/libcore/cell.rs74
1 files changed, 73 insertions, 1 deletions
diff --git a/src/libcore/cell.rs b/src/libcore/cell.rs
index 257027dad5e..57c3d9bd2fb 100644
--- a/src/libcore/cell.rs
+++ b/src/libcore/cell.rs
@@ -145,7 +145,7 @@
 #![stable(feature = "rust1", since = "1.0.0")]
 
 use clone::Clone;
-use cmp::{PartialEq, Eq};
+use cmp::{PartialEq, Eq, PartialOrd, Ord, Ordering};
 use default::Default;
 use marker::{Copy, Send, Sync, Sized, Unsize};
 use ops::{Deref, DerefMut, Drop, FnOnce, CoerceUnsized};
@@ -267,6 +267,42 @@ impl<T:PartialEq + Copy> PartialEq for Cell<T> {
 #[stable(feature = "cell_eq", since = "1.2.0")]
 impl<T:Eq + Copy> Eq for Cell<T> {}
 
+#[unstable(feature = "cell_ord", issue = "33305")]
+impl<T:PartialOrd + Copy> PartialOrd for Cell<T> {
+    #[inline]
+    fn partial_cmp(&self, other: &Cell<T>) -> Option<Ordering> {
+        self.get().partial_cmp(&other.get())
+    }
+
+    #[inline]
+    fn lt(&self, other: &Cell<T>) -> bool {
+        self.get() < other.get()
+    }
+
+    #[inline]
+    fn le(&self, other: &Cell<T>) -> bool {
+        self.get() <= other.get()
+    }
+
+    #[inline]
+    fn gt(&self, other: &Cell<T>) -> bool {
+        self.get() > other.get()
+    }
+
+    #[inline]
+    fn ge(&self, other: &Cell<T>) -> bool {
+        self.get() >= other.get()
+    }
+}
+
+#[unstable(feature = "cell_ord", issue = "33305")]
+impl<T:Ord + Copy> Ord for Cell<T> {
+    #[inline]
+    fn cmp(&self, other: &Cell<T>) -> Ordering {
+        self.get().cmp(&other.get())
+    }
+}
+
 /// A mutable memory location with dynamically checked borrow rules
 ///
 /// See the [module-level documentation](index.html) for more.
@@ -490,6 +526,42 @@ impl<T: ?Sized + PartialEq> PartialEq for RefCell<T> {
 #[stable(feature = "cell_eq", since = "1.2.0")]
 impl<T: ?Sized + Eq> Eq for RefCell<T> {}
 
+#[unstable(feature = "cell_ord", issue = "33305")]
+impl<T: ?Sized + PartialOrd> PartialOrd for RefCell<T> {
+    #[inline]
+    fn partial_cmp(&self, other: &RefCell<T>) -> Option<Ordering> {
+        self.borrow().partial_cmp(&*other.borrow())
+    }
+
+    #[inline]
+    fn lt(&self, other: &RefCell<T>) -> bool {
+        *self.borrow() < *other.borrow()
+    }
+
+    #[inline]
+    fn le(&self, other: &RefCell<T>) -> bool {
+        *self.borrow() <= *other.borrow()
+    }
+
+    #[inline]
+    fn gt(&self, other: &RefCell<T>) -> bool {
+        *self.borrow() > *other.borrow()
+    }
+
+    #[inline]
+    fn ge(&self, other: &RefCell<T>) -> bool {
+        *self.borrow() >= *other.borrow()
+    }
+}
+
+#[unstable(feature = "cell_ord", issue = "33305")]
+impl<T: ?Sized + Ord> Ord for RefCell<T> {
+    #[inline]
+    fn cmp(&self, other: &RefCell<T>) -> Ordering {
+        self.borrow().cmp(&*other.borrow())
+    }
+}
+
 struct BorrowRef<'b> {
     borrow: &'b Cell<BorrowFlag>,
 }