Skip to main content

agent_first_mail/types/
ids.rs

1use serde::{Deserialize, Serialize};
2use std::fmt;
3
4macro_rules! id_newtype {
5    ($name:ident) => {
6        #[derive(Clone, Debug, Deserialize, Serialize, PartialEq, Eq, PartialOrd, Ord, Hash)]
7        #[serde(transparent)]
8        pub struct $name(String);
9
10        impl $name {
11            pub fn new(value: impl Into<String>) -> Self {
12                Self(value.into())
13            }
14
15            pub fn as_str(&self) -> &str {
16                &self.0
17            }
18
19            pub fn into_string(self) -> String {
20                self.0
21            }
22        }
23
24        impl fmt::Display for $name {
25            fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
26                f.write_str(self.as_str())
27            }
28        }
29    };
30}
31
32id_newtype!(MessageId);
33id_newtype!(CaseUid);
34id_newtype!(ArchiveUid);
35id_newtype!(PushId);