ps_uuid/methods/
to_u128.rs1use crate::UUID;
2
3impl UUID {
4 #[must_use]
8 pub const fn to_u128(&self) -> u128 {
9 u128::from_be_bytes(self.bytes)
10 }
11}
12
13#[cfg(test)]
14mod tests {
15 use crate::UUID;
16
17 #[test]
18 fn nil_returns_zero() {
19 assert_eq!(UUID::nil().to_u128(), 0);
20 }
21
22 #[test]
23 fn max_returns_u128_max() {
24 assert_eq!(UUID::max().to_u128(), u128::MAX);
25 }
26
27 #[test]
28 fn roundtrip_with_from_u128() {
29 let value: u128 = 0x0123_4567_89ab_cdef_0123_4567_89ab_cdef;
30 let uuid = UUID::from_u128(value);
31 assert_eq!(uuid.to_u128(), value);
32 }
33
34 #[test]
35 fn const_context() {
36 const VALUE: u128 = UUID::nil().to_u128();
37 assert_eq!(VALUE, 0);
38 }
39}