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
#[macro_export]
macro_rules! entity_id {
($name:ident) => {
#[derive(Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, serde::Deserialize)]
#[serde(transparent)]
pub struct $name(uuid::Uuid);
impl $name {
#[allow(clippy::new_without_default)]
pub fn new() -> Self {
uuid::Uuid::new_v4().into()
}
}
impl From<uuid::Uuid> for $name {
fn from(uuid: uuid::Uuid) -> Self {
Self(uuid)
}
}
impl From<$name> for uuid::Uuid {
fn from(id: $name) -> Self {
id.0
}
}
impl From<$name> for cel_interpreter::CelValue {
fn from(id: $name) -> Self {
cel_interpreter::CelValue::Uuid(id.0)
}
}
impl std::fmt::Display for $name {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
impl std::str::FromStr for $name {
type Err = uuid::Error;
fn from_str(s: &str) -> Result<Self, Self::Err> {
Ok(Self(uuid::Uuid::parse_str(s)?))
}
}
};
}