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