]> git.lizzy.rs Git - rust.git/commitdiff
Implement Eq, PartialEq, Ord, PartialOrd, and Hash for NonNull<_>
authorSimon Sapin <simon.sapin@exyr.org>
Sun, 21 Jan 2018 08:51:19 +0000 (09:51 +0100)
committerSimon Sapin <simon.sapin@exyr.org>
Sun, 21 Jan 2018 09:30:24 +0000 (10:30 +0100)
src/libcore/ptr.rs

index c3b7c4f5d22471a9e172522a7cc06c12e4e25250..a0d716fb574050a5ba6fee44737d9b862735cbb7 100644 (file)
@@ -2582,6 +2582,37 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
     }
 }
 
+#[stable(feature = "nonnull", since = "1.25.0")]
+impl<T: ?Sized> Eq for NonNull<T> {}
+
+#[stable(feature = "nonnull", since = "1.25.0")]
+impl<T: ?Sized> PartialEq for NonNull<T> {
+    fn eq(&self, other: &Self) -> bool {
+        self.as_ptr() == other.as_ptr()
+    }
+}
+
+#[stable(feature = "nonnull", since = "1.25.0")]
+impl<T: ?Sized> Ord for NonNull<T> {
+    fn cmp(&self, other: &Self) -> Ordering {
+        self.as_ptr().cmp(&other.as_ptr())
+    }
+}
+
+#[stable(feature = "nonnull", since = "1.25.0")]
+impl<T: ?Sized> PartialOrd for NonNull<T> {
+    fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
+        self.as_ptr().partial_cmp(&other.as_ptr())
+    }
+}
+
+#[stable(feature = "nonnull", since = "1.25.0")]
+impl<T: ?Sized> hash::Hash for NonNull<T> {
+    fn hash<H: hash::Hasher>(&self, state: &mut H) {
+        self.as_ptr().hash(state)
+    }
+}
+
 #[stable(feature = "nonnull", since = "1.25.0")]
 impl<T: ?Sized> From<Unique<T>> for NonNull<T> {
     fn from(unique: Unique<T>) -> Self {