greentic_deploy_spec/
ids.rs1use serde::{Deserialize, Serialize};
9use std::fmt;
10use ulid::Ulid;
11
12#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
14#[serde(transparent)]
15pub struct RevisionId(pub Ulid);
16
17impl RevisionId {
18 pub fn new() -> Self {
19 Self(Ulid::new())
20 }
21}
22
23impl Default for RevisionId {
24 fn default() -> Self {
25 Self::new()
26 }
27}
28
29impl fmt::Display for RevisionId {
30 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
31 write!(f, "{}", self.0)
32 }
33}
34
35#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
37#[serde(transparent)]
38pub struct DeploymentId(pub Ulid);
39
40impl DeploymentId {
41 pub fn new() -> Self {
42 Self(Ulid::new())
43 }
44}
45
46impl Default for DeploymentId {
47 fn default() -> Self {
48 Self::new()
49 }
50}
51
52impl fmt::Display for DeploymentId {
53 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
54 write!(f, "{}", self.0)
55 }
56}
57
58#[derive(Clone, Copy, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
61#[serde(transparent)]
62pub struct MessagingEndpointId(pub Ulid);
63
64impl MessagingEndpointId {
65 pub fn new() -> Self {
66 Self(Ulid::new())
67 }
68}
69
70impl Default for MessagingEndpointId {
71 fn default() -> Self {
72 Self::new()
73 }
74}
75
76impl fmt::Display for MessagingEndpointId {
77 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
78 write!(f, "{}", self.0)
79 }
80}
81
82macro_rules! string_id {
83 ($(#[$meta:meta])* $name:ident) => {
84 $(#[$meta])*
85 #[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
86 #[serde(transparent)]
87 pub struct $name(pub String);
88
89 impl $name {
90 pub fn new(s: impl Into<String>) -> Self {
91 Self(s.into())
92 }
93
94 pub fn as_str(&self) -> &str {
95 &self.0
96 }
97 }
98
99 impl fmt::Display for $name {
100 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
101 f.write_str(&self.0)
102 }
103 }
104
105 impl From<String> for $name {
106 fn from(s: String) -> Self {
107 Self(s)
108 }
109 }
110
111 impl From<&str> for $name {
112 fn from(s: &str) -> Self {
113 Self(s.to_string())
114 }
115 }
116 };
117}
118
119string_id!(
120 BundleId
122);
123
124string_id!(
125 CustomerId
127);
128
129string_id!(
130 PackId
132);
133
134string_id!(
135 PartyId
137);