diff options
Diffstat (limited to 'lib/sellershut-core/src/users.rs')
-rw-r--r-- | lib/sellershut-core/src/users.rs | 36 |
1 files changed, 36 insertions, 0 deletions
diff --git a/lib/sellershut-core/src/users.rs b/lib/sellershut-core/src/users.rs new file mode 100644 index 0000000..5721d53 --- /dev/null +++ b/lib/sellershut-core/src/users.rs @@ -0,0 +1,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}")), + } + } +} |