1use std::fmt::{Display, Formatter, Result as FmtResult};
4
5use serde::{Deserialize, Serialize};
6
7pub type GrantId = String;
9
10macro_rules! string_id {
11 ($($(#[$doc:meta])* $name:ident;)*) => {$(
12 $(#[$doc])*
13 #[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
14 #[serde(transparent)]
15 pub struct $name(String);
16
17 impl $name {
18 pub fn as_str(&self) -> &str {
20 &self.0
21 }
22 }
23
24 impl From<String> for $name {
25 fn from(id: String) -> Self {
26 Self(id)
27 }
28 }
29
30 impl From<&str> for $name {
31 fn from(id: &str) -> Self {
32 Self(id.to_owned())
33 }
34 }
35
36 impl AsRef<str> for $name {
37 fn as_ref(&self) -> &str {
38 &self.0
39 }
40 }
41
42 impl Display for $name {
43 fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
44 f.write_str(&self.0)
45 }
46 }
47 )*};
48}
49
50string_id! {
51 ClientId;
53 OrgId;
55 ProjectId;
57 UserId;
59 WorkloadId;
61}