Skip to main content

bitwarden_api_api/models/
client_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///
15#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
16pub enum ClientType {
17    All,
18    Web,
19    Browser,
20    Desktop,
21    Mobile,
22    Cli,
23
24    /// Unknown value returned from the server. This is used to handle forward compatibility.
25    __Unknown(i64),
26}
27
28impl ClientType {
29    pub fn as_i64(&self) -> i64 {
30        match self {
31            Self::All => 0,
32            Self::Web => 1,
33            Self::Browser => 2,
34            Self::Desktop => 3,
35            Self::Mobile => 4,
36            Self::Cli => 5,
37            Self::__Unknown(v) => *v,
38        }
39    }
40
41    pub fn from_i64(value: i64) -> Self {
42        match value {
43            0 => Self::All,
44            1 => Self::Web,
45            2 => Self::Browser,
46            3 => Self::Desktop,
47            4 => Self::Mobile,
48            5 => Self::Cli,
49            v => Self::__Unknown(v),
50        }
51    }
52}
53
54impl serde::Serialize for ClientType {
55    fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
56        serializer.serialize_i64(self.as_i64())
57    }
58}
59
60impl<'de> serde::Deserialize<'de> for ClientType {
61    fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
62        struct ClientTypeVisitor;
63
64        impl Visitor<'_> for ClientTypeVisitor {
65            type Value = ClientType;
66
67            fn expecting(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
68                f.write_str("an integer")
69            }
70
71            fn visit_i64<E: serde::de::Error>(self, v: i64) -> Result<Self::Value, E> {
72                Ok(ClientType::from_i64(v))
73            }
74
75            fn visit_u64<E: serde::de::Error>(self, v: u64) -> Result<Self::Value, E> {
76                Ok(ClientType::from_i64(v as i64))
77            }
78        }
79
80        deserializer.deserialize_i64(ClientTypeVisitor)
81    }
82}
83
84impl std::fmt::Display for ClientType {
85    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
86        write!(f, "{}", self.as_i64())
87    }
88}
89impl Default for ClientType {
90    fn default() -> ClientType {
91        Self::All
92    }
93}