1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
//! Stable identifiers used by control-plane management operations.
use std::fmt::{Display, Formatter, Result as FmtResult};
use serde::{Deserialize, Serialize};
/// A Project authorization grant identifier.
pub type GrantId = String;
macro_rules! string_id {
($($(#[$doc:meta])* $name:ident;)*) => {$(
$(#[$doc])*
#[derive(Clone, Debug, PartialEq, Eq, Hash, PartialOrd, Ord, Serialize, Deserialize)]
#[serde(transparent)]
pub struct $name(String);
impl $name {
/// The identifier as the API spells it.
pub fn as_str(&self) -> &str {
&self.0
}
}
impl From<String> for $name {
fn from(id: String) -> Self {
Self(id)
}
}
impl From<&str> for $name {
fn from(id: &str) -> Self {
Self(id.to_owned())
}
}
impl AsRef<str> for $name {
fn as_ref(&self) -> &str {
&self.0
}
}
impl Display for $name {
fn fmt(&self, f: &mut Formatter<'_>) -> FmtResult {
f.write_str(&self.0)
}
}
)*};
}
string_id! {
/// An OAuth client: an application, a workload or an installation.
ClientId;
/// An organization.
OrgId;
/// A project.
ProjectId;
/// A user.
UserId;
/// A workload: a non-human identity that runs jobs in a project.
WorkloadId;
}