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
use std::fmt;
use uuid::Uuid;
#[derive(PartialEq, Eq, Hash, Copy, Clone, PartialOrd, Ord)]
pub struct ID(Uuid);
impl ID {
#[inline]
pub fn new() -> Self {
Self::default()
}
#[inline]
pub fn uuid(&self) -> Uuid {
self.0
}
}
impl Default for ID {
#[inline]
fn default() -> Self {
ID(Uuid::new_v4())
}
}
impl fmt::Debug for ID {
#[inline]
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "{}", self.to_string())
}
}
impl ToString for ID {
#[inline]
fn to_string(&self) -> String {
format!("ID({})", self.0)
}
}