mirror of
https://github.com/uuid-rs/uuid.git
synced 2025-10-02 07:20:40 +00:00
Merge pull request #808 from rick-de-water/nonnil-debug-format
Add a manual `Debug` implementation for NonNilUUid
This commit is contained in:
commit
a3eaab0870
@ -33,12 +33,18 @@ use crate::{
|
|||||||
/// may change. It is currently only guaranteed that `NonNilUuid` and `Option<NonNilUuid>`
|
/// may change. It is currently only guaranteed that `NonNilUuid` and `Option<NonNilUuid>`
|
||||||
/// are the same size as `Uuid`.
|
/// are the same size as `Uuid`.
|
||||||
#[repr(transparent)]
|
#[repr(transparent)]
|
||||||
#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)]
|
#[derive(Copy, Clone, PartialEq, Eq, Hash)]
|
||||||
pub struct NonNilUuid(NonZeroU128);
|
pub struct NonNilUuid(NonZeroU128);
|
||||||
|
|
||||||
|
impl fmt::Debug for NonNilUuid {
|
||||||
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
|
fmt::Debug::fmt(&Uuid::from(*self), f)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl fmt::Display for NonNilUuid {
|
impl fmt::Display for NonNilUuid {
|
||||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||||
write!(f, "{}", Uuid::from(*self))
|
fmt::Display::fmt(&Uuid::from(*self), f)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -139,4 +145,13 @@ mod tests {
|
|||||||
assert!(NonNilUuid::try_from(Uuid::nil()).is_err());
|
assert!(NonNilUuid::try_from(Uuid::nil()).is_err());
|
||||||
assert!(NonNilUuid::new(Uuid::nil()).is_none());
|
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:?}"));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user