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
|
tonic::include_proto!("users");
/// Users file descriptor
pub const USERS_FILE_DESCRIPTOR_SET: &[u8] =
tonic::include_file_descriptor_set!("users_descriptor");
impl std::fmt::Display for UserType {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
"{}",
match self {
UserType::Person => "person",
UserType::Application => "application",
UserType::Group => "group",
UserType::Organization => "organization",
UserType::Service => "service",
}
.to_uppercase()
)
}
}
impl std::str::FromStr for UserType {
type Err = String;
fn from_str(value: &str) -> Result<Self, Self::Err> {
match value.to_lowercase().as_str() {
"person" => Ok(Self::Person),
"application" => Ok(Self::Application),
"group" => Ok(Self::Group),
"organization" => Ok(Self::Organization),
"service" => Ok(Self::Service),
_ => Err(format!("invalid user type: {value}")),
}
}
}
|