1use core::fmt;
10use core::str::FromStr;
11
12use serde::Deserialize;
13use serde::Serialize;
14use uuid::Uuid;
15
16#[derive(Copy, Clone, Eq, PartialEq, Hash, Serialize, Deserialize)]
18pub struct Id(Uuid);
19
20impl Id {
21 pub fn unique() -> Self {
23 Self(Uuid::new_v4())
24 }
25}
26
27impl FromStr for Id {
28 type Err = <Uuid as FromStr>::Err;
29
30 fn from_str(s: &str) -> Result<Self, Self::Err> {
31 Uuid::from_str(s).map(Self)
32 }
33}
34
35impl fmt::Display for Id {
36 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
37 fmt::Display::fmt(&self.0.as_simple(), f)
38 }
39}
40
41impl fmt::Debug for Id {
42 fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
43 fmt::Display::fmt(&self.0.as_simple(), f)
44 }
45}