1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
use byteorder;
use prelude::*;
impl Uuid {
#[inline]
pub fn from_u128(quad: u128) -> Self {
Uuid::from(quad)
}
}
impl From<u128> for Uuid {
fn from(f: u128) -> Self {
let mut bytes: ::Bytes = [0; 16];
{
use byteorder::ByteOrder;
byteorder::NativeEndian::write_u128(&mut bytes[..], f);
}
Uuid::from_bytes(bytes)
}
}
#[cfg(test)]
mod tests {
use prelude::*;
#[test]
fn test_from_u128() {
const U128: u128 = 0x3a0724b4_93a0_4d87_ac28_759c6caa13c4;
let uuid = Uuid::from(U128);
let uuid2: Uuid = U128.into();
assert_eq!(uuid, uuid2)
}
}