systemprompt_models/auth/enums/
account_kind.rs1use serde::{Deserialize, Serialize};
11use std::fmt;
12use std::str::FromStr;
13
14use crate::errors::ParseEnumError;
15
16#[derive(Debug, Clone, Copy, Default, PartialEq, Eq, Hash, Serialize, Deserialize)]
17#[serde(rename_all = "lowercase")]
18pub enum AccountKind {
19 #[default]
20 Person,
21 Service,
22}
23
24impl AccountKind {
25 pub const fn as_str(&self) -> &'static str {
26 match self {
27 Self::Person => "person",
28 Self::Service => "service",
29 }
30 }
31
32 pub const fn is_service(&self) -> bool {
33 matches!(self, Self::Service)
34 }
35
36 pub const fn allows_interactive_login(&self) -> bool {
37 matches!(self, Self::Person)
38 }
39}
40
41impl fmt::Display for AccountKind {
42 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
43 f.write_str(self.as_str())
44 }
45}
46
47impl FromStr for AccountKind {
48 type Err = ParseEnumError;
49 fn from_str(s: &str) -> Result<Self, Self::Err> {
50 match s {
51 "person" => Ok(Self::Person),
52 "service" => Ok(Self::Service),
53 _ => Err(ParseEnumError::new("account_kind", s)),
54 }
55 }
56}