Skip to main content

ps_uuid/implementations/
debug.rs

1use std::fmt;
2
3use crate::UUID;
4
5impl fmt::Debug for UUID {
6    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
7        write!(f, "{{{self}}}")
8    }
9}
10
11#[cfg(test)]
12mod tests {
13    #![allow(clippy::expect_used)]
14    use super::UUID;
15    use core::str::FromStr;
16
17    #[test]
18    fn test_uuid_debug() {
19        let uuid = UUID {
20            bytes: [
21                0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E,
22                0x0F, 0x10,
23            ],
24        };
25        assert_eq!(
26            format!("{uuid:?}"),
27            "{01020304-0506-0708-090a-0b0c0d0e0f10}"
28        );
29    }
30
31    #[test]
32    fn test_uuid_debug_roundtrip() {
33        let uuid = UUID {
34            bytes: [
35                0x6b, 0xa7, 0xb8, 0x10, 0x9d, 0xad, 0x11, 0xd1, 0x80, 0xb4, 0x00, 0xc0, 0x4f, 0xd4,
36                0x30, 0xc8,
37            ],
38        };
39        let debug = format!("{uuid:?}");
40        let parsed = UUID::from_str(&debug).expect("failed to parse UUID from Debug output");
41        assert_eq!(parsed, uuid);
42    }
43}