1use serde::{Deserialize, Serialize};
3use std::fmt;
4
5macro_rules! name {
6 ($(#[$m:meta])* $t:ident) => {
7 $(#[$m])*
8 #[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
9 #[serde(transparent)]
10 pub struct $t(pub String);
11
12 impl $t {
13 pub fn new(s: impl Into<String>) -> Self {
15 $t(s.into())
16 }
17
18 pub fn as_str(&self) -> &str {
20 &self.0
21 }
22 }
23
24 impl fmt::Display for $t {
25 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
26 f.write_str(&self.0)
27 }
28 }
29
30 impl From<&str> for $t {
31 fn from(s: &str) -> Self {
32 $t(s.to_string())
33 }
34 }
35 };
36}
37
38name!(
39 ProjectId
41);
42name!(
43 RoleId
45);
46name!(
47 Permission
49);
50name!(
51 StreamId
53);
54name!(
55 RecordId
57);