1use std::{fmt, str::FromStr};
2
3use serde::{Deserialize, Serialize};
4use uuid::Uuid;
5
6macro_rules! define_id {
7 ($name:ident) => {
8 #[derive(
9 Debug, Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Hash, Serialize, Deserialize,
10 )]
11 #[serde(transparent)]
12 pub struct $name(pub Uuid);
13
14 impl $name {
15 pub fn new() -> Self {
16 Self(Uuid::now_v7())
17 }
18 }
19
20 impl Default for $name {
21 fn default() -> Self {
22 Self::new()
23 }
24 }
25
26 impl fmt::Display for $name {
27 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
28 self.0.fmt(f)
29 }
30 }
31
32 impl FromStr for $name {
33 type Err = uuid::Error;
34
35 fn from_str(s: &str) -> Result<Self, Self::Err> {
36 Ok(Self(Uuid::parse_str(s)?))
37 }
38 }
39 };
40}
41
42define_id!(WindowId);
43define_id!(WorkspaceId);
44define_id!(WorkspaceColumnId);
45define_id!(WorkspaceWindowId);
46define_id!(WorkspaceWindowTabId);
47define_id!(PaneContainerId);
48define_id!(PaneTabId);
49define_id!(PaneId);
50define_id!(SurfaceId);
51define_id!(SessionId);
52define_id!(NotificationId);