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