bitwarden_api_api/models/
pam_rotation_attempt_status.rs1use serde::{Deserialize, Deserializer, Serialize, Serializer, de::Visitor};
12
13use crate::models;
14#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
16pub enum PamRotationAttemptStatus {
17 Executing,
18 Rotated,
19 Errored,
20 Abandoned,
21
22 __Unknown(i64),
24}
25
26impl PamRotationAttemptStatus {
27 pub fn as_i64(&self) -> i64 {
28 match self {
29 Self::Executing => 0,
30 Self::Rotated => 1,
31 Self::Errored => 2,
32 Self::Abandoned => 3,
33 Self::__Unknown(v) => *v,
34 }
35 }
36
37 pub fn from_i64(value: i64) -> Self {
38 match value {
39 0 => Self::Executing,
40 1 => Self::Rotated,
41 2 => Self::Errored,
42 3 => Self::Abandoned,
43 v => Self::__Unknown(v),
44 }
45 }
46}
47
48impl serde::Serialize for PamRotationAttemptStatus {
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 PamRotationAttemptStatus {
55 fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
56 struct PamRotationAttemptStatusVisitor;
57
58 impl Visitor<'_> for PamRotationAttemptStatusVisitor {
59 type Value = PamRotationAttemptStatus;
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(PamRotationAttemptStatus::from_i64(v))
67 }
68
69 fn visit_u64<E: serde::de::Error>(self, v: u64) -> Result<Self::Value, E> {
70 Ok(PamRotationAttemptStatus::from_i64(v as i64))
71 }
72 }
73
74 deserializer.deserialize_i64(PamRotationAttemptStatusVisitor)
75 }
76}
77
78impl std::fmt::Display for PamRotationAttemptStatus {
79 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
80 write!(f, "{}", self.as_i64())
81 }
82}
83impl Default for PamRotationAttemptStatus {
84 fn default() -> PamRotationAttemptStatus {
85 Self::Executing
86 }
87}