diff --git a/src/non_nil.rs b/src/non_nil.rs index ee235a1..5507037 100644 --- a/src/non_nil.rs +++ b/src/non_nil.rs @@ -33,9 +33,15 @@ use crate::{ /// may change. It is currently only guaranteed that `NonNilUuid` and `Option` /// are the same size as `Uuid`. #[repr(transparent)] -#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +#[derive(Copy, Clone, PartialEq, Eq, Hash)] pub struct NonNilUuid(NonZeroU128); +impl fmt::Debug for NonNilUuid { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + write!(f, "{}", Uuid::from(*self)) + } +} + impl fmt::Display for NonNilUuid { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{}", Uuid::from(*self)) @@ -139,4 +145,13 @@ mod tests { assert!(NonNilUuid::try_from(Uuid::nil()).is_err()); assert!(NonNilUuid::new(Uuid::nil()).is_none()); } + + #[test] + fn test_non_nil_formatting() { + let uuid = Uuid::from_u128(0x0123456789abcdef0123456789abcdef); + let non_nil = NonNilUuid::try_from(uuid).unwrap(); + + assert_eq!(format!("{uuid}"), format!("{non_nil}")); + assert_eq!(format!("{uuid:?}"), format!("{non_nil:?}")); + } }