Skip to content

Commit 6461c9b

Browse files
committed
Implement Eq, PartialEq, Ord, PartialOrd, and Hash for NonNull<_>
1 parent ad37e3f commit 6461c9b

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

src/libcore/ptr.rs

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2582,6 +2582,37 @@ impl<T: ?Sized> fmt::Pointer for NonNull<T> {
25822582
}
25832583
}
25842584

2585+
#[stable(feature = "nonnull", since = "1.25.0")]
2586+
impl<T: ?Sized> Eq for NonNull<T> {}
2587+
2588+
#[stable(feature = "nonnull", since = "1.25.0")]
2589+
impl<T: ?Sized> PartialEq for NonNull<T> {
2590+
fn eq(&self, other: &Self) -> bool {
2591+
self.as_ptr() == other.as_ptr()
2592+
}
2593+
}
2594+
2595+
#[stable(feature = "nonnull", since = "1.25.0")]
2596+
impl<T: ?Sized> Ord for NonNull<T> {
2597+
fn cmp(&self, other: &Self) -> Ordering {
2598+
self.as_ptr().cmp(&other.as_ptr())
2599+
}
2600+
}
2601+
2602+
#[stable(feature = "nonnull", since = "1.25.0")]
2603+
impl<T: ?Sized> PartialOrd for NonNull<T> {
2604+
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
2605+
self.as_ptr().partial_cmp(&other.as_ptr())
2606+
}
2607+
}
2608+
2609+
#[stable(feature = "nonnull", since = "1.25.0")]
2610+
impl<T: ?Sized> hash::Hash for NonNull<T> {
2611+
fn hash<H: hash::Hasher>(&self, state: &mut H) {
2612+
self.as_ptr().hash(state)
2613+
}
2614+
}
2615+
25852616
#[stable(feature = "nonnull", since = "1.25.0")]
25862617
impl<T: ?Sized> From<Unique<T>> for NonNull<T> {
25872618
fn from(unique: Unique<T>) -> Self {

0 commit comments

Comments
 (0)