diff --git a/src/lib.rs b/src/lib.rs index d9d772cf..46abceb5 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -438,6 +438,7 @@ pub enum Variant { /// The `Uuid` type is always guaranteed to be have the same ABI as [`Bytes`]. #[derive(Clone, Copy, Eq, Hash, Ord, PartialEq, PartialOrd)] #[repr(transparent)] +// NOTE: Also check `NonNilUuid` when ading new derives here #[cfg_attr( all(uuid_unstable, feature = "zerocopy"), derive(IntoBytes, FromBytes, KnownLayout, Immutable, Unaligned) diff --git a/src/non_nil.rs b/src/non_nil.rs index f88fd1a2..66bd0ba9 100644 --- a/src/non_nil.rs +++ b/src/non_nil.rs @@ -44,6 +44,18 @@ impl fmt::Display for NonNilUuid { } } +impl PartialEq for NonNilUuid { + fn eq(&self, other: &Uuid) -> bool { + self.get() == *other + } +} + +impl PartialEq for Uuid { + fn eq(&self, other: &NonNilUuid) -> bool { + *self == other.get() + } +} + impl NonNilUuid { /// Creates a non-nil UUID if the value is non-nil. pub const fn new(uuid: Uuid) -> Option { @@ -125,8 +137,8 @@ mod tests { let uuid = Uuid::from_u128(0x0123456789abcdef0123456789abcdef); assert_eq!(Uuid::from(NonNilUuid::try_from(uuid).unwrap()), uuid); - assert_eq!(NonNilUuid::new(uuid).unwrap().get(), uuid); - assert_eq!(unsafe { NonNilUuid::new_unchecked(uuid) }.get(), uuid); + assert_eq!(NonNilUuid::new(uuid).unwrap(), uuid); + assert_eq!(unsafe { NonNilUuid::new_unchecked(uuid) }, uuid); assert!(NonNilUuid::try_from(Uuid::nil()).is_err()); assert!(NonNilUuid::new(Uuid::nil()).is_none());