1use serde::{Deserialize, Serialize};
4use uuid::Uuid;
5
6#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
8pub struct IncarnationId(pub Uuid);
9
10impl IncarnationId {
11 pub fn new() -> Self {
12 Self(Uuid::new_v4())
13 }
14
15 pub fn from_context(context: &str) -> Self {
16 let namespace = Uuid::NAMESPACE_OID;
17 Self(Uuid::new_v5(&namespace, context.as_bytes()))
18 }
19
20 pub fn as_uuid(&self) -> &Uuid {
21 &self.0
22 }
23}
24
25impl Default for IncarnationId {
26 fn default() -> Self {
27 Self::new()
28 }
29}
30
31impl std::fmt::Display for IncarnationId {
32 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
33 write!(f, "{}", self.0)
34 }
35}
36
37#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
39pub struct ContextId(pub Uuid);
40
41impl ContextId {
42 pub fn new() -> Self {
43 Self(Uuid::new_v4())
44 }
45}
46
47impl Default for ContextId {
48 fn default() -> Self {
49 Self::new()
50 }
51}
52
53impl std::fmt::Display for ContextId {
54 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
55 write!(f, "{}", self.0)
56 }
57}
58
59#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
61pub struct AnchorId(pub Uuid);
62
63impl AnchorId {
64 pub fn new() -> Self {
65 Self(Uuid::new_v4())
66 }
67}
68
69impl Default for AnchorId {
70 fn default() -> Self {
71 Self::new()
72 }
73}
74
75impl std::fmt::Display for AnchorId {
76 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
77 write!(f, "{}", self.0)
78 }
79}
80
81#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
83pub struct TimelineId(pub Uuid);
84
85impl TimelineId {
86 pub fn new() -> Self {
87 Self(Uuid::new_v4())
88 }
89}
90
91impl Default for TimelineId {
92 fn default() -> Self {
93 Self::new()
94 }
95}
96
97impl std::fmt::Display for TimelineId {
98 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
99 write!(f, "{}", self.0)
100 }
101}
102
103#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
105pub struct TransitionId(pub Uuid);
106
107impl TransitionId {
108 pub fn new() -> Self {
109 Self(Uuid::new_v4())
110 }
111}
112
113impl Default for TransitionId {
114 fn default() -> Self {
115 Self::new()
116 }
117}
118
119impl std::fmt::Display for TransitionId {
120 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
121 write!(f, "{}", self.0)
122 }
123}
124
125#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
127pub struct EventId(pub Uuid);
128
129impl EventId {
130 pub fn new() -> Self {
131 Self(Uuid::new_v4())
132 }
133}
134
135impl Default for EventId {
136 fn default() -> Self {
137 Self::new()
138 }
139}
140
141impl std::fmt::Display for EventId {
142 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
143 write!(f, "{}", self.0)
144 }
145}
146
147#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
149pub struct ServiceId(pub String);
150
151impl ServiceId {
152 pub fn new(id: impl Into<String>) -> Self {
153 Self(id.into())
154 }
155}
156
157impl std::fmt::Display for ServiceId {
158 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
159 write!(f, "{}", self.0)
160 }
161}
162
163#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
165pub struct DependencyId(pub Uuid);
166
167impl DependencyId {
168 pub fn new() -> Self {
169 Self(Uuid::new_v4())
170 }
171}
172
173impl Default for DependencyId {
174 fn default() -> Self {
175 Self::new()
176 }
177}
178
179impl std::fmt::Display for DependencyId {
180 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
181 write!(f, "{}", self.0)
182 }
183}
184
185#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
187pub struct NeighborId(pub String);
188
189impl NeighborId {
190 pub fn new(id: impl Into<String>) -> Self {
191 Self(id.into())
192 }
193}
194
195impl std::fmt::Display for NeighborId {
196 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
197 write!(f, "{}", self.0)
198 }
199}
200
201#[derive(Debug, Clone, PartialEq, Eq, Hash, Serialize, Deserialize)]
203pub struct ObserverId(pub String);
204
205impl ObserverId {
206 pub fn new(id: impl Into<String>) -> Self {
207 Self(id.into())
208 }
209}
210
211impl std::fmt::Display for ObserverId {
212 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
213 write!(f, "{}", self.0)
214 }
215}
216
217#[derive(Debug, Clone, Copy, PartialEq, Eq, Hash, Serialize, Deserialize)]
219pub struct SnapshotId(pub Uuid);
220
221impl SnapshotId {
222 pub fn new() -> Self {
223 Self(Uuid::new_v4())
224 }
225}
226
227impl Default for SnapshotId {
228 fn default() -> Self {
229 Self::new()
230 }
231}
232
233impl std::fmt::Display for SnapshotId {
234 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
235 write!(f, "{}", self.0)
236 }
237}
238
239#[cfg(test)]
240mod tests {
241 use super::*;
242
243 #[test]
244 fn test_incarnation_id_new() {
245 let id1 = IncarnationId::new();
246 let id2 = IncarnationId::new();
247 assert_ne!(id1, id2);
248 }
249
250 #[test]
251 fn test_incarnation_id_from_context() {
252 let id1 = IncarnationId::from_context("test-context");
253 let id2 = IncarnationId::from_context("test-context");
254 assert_eq!(id1, id2);
255 }
256
257 #[test]
258 fn test_context_id_uniqueness() {
259 let id1 = ContextId::new();
260 let id2 = ContextId::new();
261 assert_ne!(id1, id2);
262 }
263
264 #[test]
265 fn test_service_id_display() {
266 let sid = ServiceId::new("my-service");
267 assert_eq!(sid.to_string(), "my-service");
268 }
269}