bitwarden_api_api/models/
auth_request_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 AuthRequestType {
17 AuthenticateAndUnlock,
18 Unlock,
19 AdminApproval,
20
21 __Unknown(i64),
23}
24
25impl AuthRequestType {
26 pub fn as_i64(&self) -> i64 {
27 match self {
28 Self::AuthenticateAndUnlock => 0,
29 Self::Unlock => 1,
30 Self::AdminApproval => 2,
31 Self::__Unknown(v) => *v,
32 }
33 }
34
35 pub fn from_i64(value: i64) -> Self {
36 match value {
37 0 => Self::AuthenticateAndUnlock,
38 1 => Self::Unlock,
39 2 => Self::AdminApproval,
40 v => Self::__Unknown(v),
41 }
42 }
43}
44
45impl serde::Serialize for AuthRequestType {
46 fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
47 serializer.serialize_i64(self.as_i64())
48 }
49}
50
51impl<'de> serde::Deserialize<'de> for AuthRequestType {
52 fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
53 struct AuthRequestTypeVisitor;
54
55 impl Visitor<'_> for AuthRequestTypeVisitor {
56 type Value = AuthRequestType;
57
58 fn expecting(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
59 f.write_str("an integer")
60 }
61
62 fn visit_i64<E: serde::de::Error>(self, v: i64) -> Result<Self::Value, E> {
63 Ok(AuthRequestType::from_i64(v))
64 }
65
66 fn visit_u64<E: serde::de::Error>(self, v: u64) -> Result<Self::Value, E> {
67 Ok(AuthRequestType::from_i64(v as i64))
68 }
69 }
70
71 deserializer.deserialize_i64(AuthRequestTypeVisitor)
72 }
73}
74
75impl std::fmt::Display for AuthRequestType {
76 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
77 write!(f, "{}", self.as_i64())
78 }
79}
80impl Default for AuthRequestType {
81 fn default() -> AuthRequestType {
82 Self::AuthenticateAndUnlock
83 }
84}