1use std::fmt::{self, Display, Formatter};
2
3use uuid::Uuid;
4
5#[derive(
6 Clone, Copy, Debug, Eq, Hash, Ord, PartialEq, PartialOrd, serde::Deserialize, serde::Serialize,
7)]
8#[serde(rename_all = "lowercase")]
9pub struct Id(pub Uuid);
10
11impl Id {
12 pub fn new() -> Self {
13 Self(Uuid::new_v4())
14 }
15}
16
17impl Default for Id {
18 fn default() -> Self {
19 Self(Uuid::max())
20 }
21}
22
23impl Display for Id {
24 fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
25 let (fst, snd, thrd, _frth) = self.0.as_fields();
26 let id = (fst as u64) << 32 | (snd as u64) << 16 | (thrd as u64);
27 id.fmt(f)
28 }
29}