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
58
59
60
61
62
63
64
65
66
67
//! Legacy shared API types.
//!
//! New code should prefer IDs defined next to endpoint modules (for example
//! `api::server::ServerId`, `api::domains::DomainId`).
macro_rules! id_type {
($vis:vis $name:ident) => {
#[derive(
Debug,
Clone,
Copy,
Default,
PartialEq,
Eq,
PartialOrd,
Ord,
Hash,
serde::Serialize,
serde::Deserialize,
)]
#[serde(transparent)]
#[repr(transparent)]
$vis struct $name(i64);
impl $name {
pub const fn new(value: i64) -> Self {
Self(value)
}
pub const fn get(self) -> i64 {
self.0
}
}
impl std::fmt::Display for $name {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(f, "{}", self.0)
}
}
impl From<i64> for $name {
fn from(value: i64) -> Self {
Self(value)
}
}
impl From<$name> for i64 {
fn from(value: $name) -> Self {
value.0
}
}
impl PartialEq<i64> for $name {
fn eq(&self, other: &i64) -> bool {
self.0 == *other
}
}
impl PartialEq<$name> for i64 {
fn eq(&self, other: &$name) -> bool {
*self == other.0
}
}
};
}
pub(crate) use id_type;