Skip to main content

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