Skip to main content

bitwarden_api_api/models/
auth_type.rs

1/*
2 * Bitwarden Internal API
3 *
4 * No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator)
5 *
6 * The version of the OpenAPI document: latest
7 *
8 * Generated by: https://openapi-generator.tech
9 */
10
11use serde::{Deserialize, Deserializer, Serialize, Serializer, de::Visitor};
12
13use crate::models;
14/// AuthType : Specifies the authentication method required to access a Send.
15/// Specifies the authentication method required to access a Send.
16#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
17pub enum AuthType {
18    Email,
19    Password,
20    None,
21
22    /// Unknown value returned from the server. This is used to handle forward compatibility.
23    __Unknown(i64),
24}
25
26impl AuthType {
27    pub fn as_i64(&self) -> i64 {
28        match self {
29            Self::Email => 0,
30            Self::Password => 1,
31            Self::None => 2,
32            Self::__Unknown(v) => *v,
33        }
34    }
35
36    pub fn from_i64(value: i64) -> Self {
37        match value {
38            0 => Self::Email,
39            1 => Self::Password,
40            2 => Self::None,
41            v => Self::__Unknown(v),
42        }
43    }
44}
45
46impl serde::Serialize for AuthType {
47    fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
48        serializer.serialize_i64(self.as_i64())
49    }
50}
51
52impl<'de> serde::Deserialize<'de> for AuthType {
53    fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
54        struct AuthTypeVisitor;
55
56        impl Visitor<'_> for AuthTypeVisitor {
57            type Value = AuthType;
58
59            fn expecting(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
60                f.write_str("an integer")
61            }
62
63            fn visit_i64<E: serde::de::Error>(self, v: i64) -> Result<Self::Value, E> {
64                Ok(AuthType::from_i64(v))
65            }
66
67            fn visit_u64<E: serde::de::Error>(self, v: u64) -> Result<Self::Value, E> {
68                Ok(AuthType::from_i64(v as i64))
69            }
70        }
71
72        deserializer.deserialize_i64(AuthTypeVisitor)
73    }
74}
75
76impl std::fmt::Display for AuthType {
77    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
78        write!(f, "{}", self.as_i64())
79    }
80}
81impl Default for AuthType {
82    fn default() -> AuthType {
83        Self::Email
84    }
85}