Skip to main content

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