bitwarden_api_api/models/
organization_user_type.rs1use serde::{Deserialize, Deserializer, Serialize, Serializer, de::Visitor};
12
13use crate::models;
14#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
16pub enum OrganizationUserType {
17 Owner,
18 Admin,
19 User,
20 Custom,
21
22 __Unknown(i64),
24}
25
26impl OrganizationUserType {
27 pub fn as_i64(&self) -> i64 {
28 match self {
29 Self::Owner => 0,
30 Self::Admin => 1,
31 Self::User => 2,
32 Self::Custom => 4,
33 Self::__Unknown(v) => *v,
34 }
35 }
36
37 pub fn from_i64(value: i64) -> Self {
38 match value {
39 0 => Self::Owner,
40 1 => Self::Admin,
41 2 => Self::User,
42 4 => Self::Custom,
43 v => Self::__Unknown(v),
44 }
45 }
46}
47
48impl serde::Serialize for OrganizationUserType {
49 fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
50 serializer.serialize_i64(self.as_i64())
51 }
52}
53
54impl<'de> serde::Deserialize<'de> for OrganizationUserType {
55 fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
56 struct OrganizationUserTypeVisitor;
57
58 impl Visitor<'_> for OrganizationUserTypeVisitor {
59 type Value = OrganizationUserType;
60
61 fn expecting(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
62 f.write_str("an integer")
63 }
64
65 fn visit_i64<E: serde::de::Error>(self, v: i64) -> Result<Self::Value, E> {
66 Ok(OrganizationUserType::from_i64(v))
67 }
68
69 fn visit_u64<E: serde::de::Error>(self, v: u64) -> Result<Self::Value, E> {
70 Ok(OrganizationUserType::from_i64(v as i64))
71 }
72 }
73
74 deserializer.deserialize_i64(OrganizationUserTypeVisitor)
75 }
76}
77
78impl std::fmt::Display for OrganizationUserType {
79 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
80 write!(f, "{}", self.as_i64())
81 }
82}
83impl Default for OrganizationUserType {
84 fn default() -> OrganizationUserType {
85 Self::Owner
86 }
87}