diff options
| author | Simon Sapin <simon.sapin@exyr.org> | 2018-01-21 09:51:19 +0100 |
|---|---|---|
| committer | Simon Sapin <simon.sapin@exyr.org> | 2018-01-21 10:30:24 +0100 |
| commit | 6461c9bdd35d6273b88f22fd5e8708eaf8949283 (patch) | |
| tree | 8c3623c3c969f6632fc65d1a46bdb25948c7067f | |
| parent | ad37e3fc01b533994dfb30f703c28ecdbf66fe10 (diff) | |
| download | rust-6461c9bdd35d6273b88f22fd5e8708eaf8949283.tar.gz rust-6461c9bdd35d6273b88f22fd5e8708eaf8949283.zip | |
Implement Eq, PartialEq, Ord, PartialOrd, and Hash for NonNull<_>
| -rw-r--r-- | src/libcore/ptr.rs | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index c3b7c4f5d22..a0d716fb574 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -2583,6 +2583,37 @@ impl<T: ?Sized> fmt::Pointer for NonNull<T> { } #[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 { NonNull { pointer: unique.pointer } |
