1use serde::{Deserialize, Serialize};
8use std::fmt;
9
10macro_rules! string_id {
11 ($(#[$meta:meta])* $name:ident) => {
12 $(#[$meta])*
13 #[derive(Clone, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
14 #[serde(transparent)]
15 pub struct $name(pub String);
16
17 impl $name {
18 pub fn new(value: impl Into<String>) -> Self {
19 Self(value.into())
20 }
21
22 pub fn as_str(&self) -> &str {
23 &self.0
24 }
25 }
26
27 impl fmt::Display for $name {
28 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
29 f.write_str(&self.0)
30 }
31 }
32
33 impl fmt::Debug for $name {
34 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
35 write!(f, concat!(stringify!($name), "({:?})"), self.0)
36 }
37 }
38
39 impl From<String> for $name {
40 fn from(value: String) -> Self {
41 Self(value)
42 }
43 }
44
45 impl From<&str> for $name {
46 fn from(value: &str) -> Self {
47 Self(value.to_owned())
48 }
49 }
50 };
51}
52
53string_id!(
54 SessionId
56);
57string_id!(
58 UserId
60);
61string_id!(
62 UserKeyId
64);
65string_id!(
66 AddressId
68);
69string_id!(
70 AddressKeyId
72);
73string_id!(
74 VolumeId
76);
77string_id!(
78 ShareId
80);
81string_id!(
82 LinkId
84);
85string_id!(
86 DriveEventId
88);
89string_id!(
90 ShareMembershipId
92);
93string_id!(
94 DeviceUid
100);
101
102#[derive(Clone, PartialEq, Eq, Hash, Debug, Serialize, Deserialize)]
104pub struct NodeUid {
105 pub volume_id: VolumeId,
106 pub link_id: LinkId,
107}
108
109impl NodeUid {
110 pub fn new(volume_id: VolumeId, link_id: LinkId) -> Self {
111 Self { volume_id, link_id }
112 }
113}
114
115impl fmt::Display for NodeUid {
116 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
117 write!(f, "{}~{}", self.volume_id, self.link_id)
118 }
119}