bitwarden_api_api/models/
plan_cadence_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 PlanCadenceType {
17    Annually,
18    Monthly,
19
20    /// Unknown value returned from the server. This is used to handle forward compatibility.
21    __Unknown(i64),
22}
23
24impl PlanCadenceType {
25    pub fn as_i64(&self) -> i64 {
26        match self {
27            Self::Annually => 0,
28            Self::Monthly => 1,
29            Self::__Unknown(v) => *v,
30        }
31    }
32
33    pub fn from_i64(value: i64) -> Self {
34        match value {
35            0 => Self::Annually,
36            1 => Self::Monthly,
37            v => Self::__Unknown(v),
38        }
39    }
40}
41
42impl serde::Serialize for PlanCadenceType {
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 PlanCadenceType {
49    fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
50        struct PlanCadenceTypeVisitor;
51
52        impl Visitor<'_> for PlanCadenceTypeVisitor {
53            type Value = PlanCadenceType;
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(PlanCadenceType::from_i64(v))
61            }
62
63            fn visit_u64<E: serde::de::Error>(self, v: u64) -> Result<Self::Value, E> {
64                Ok(PlanCadenceType::from_i64(v as i64))
65            }
66        }
67
68        deserializer.deserialize_i64(PlanCadenceTypeVisitor)
69    }
70}
71
72impl std::fmt::Display for PlanCadenceType {
73    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
74        write!(f, "{}", self.as_i64())
75    }
76}
77impl Default for PlanCadenceType {
78    fn default() -> PlanCadenceType {
79        Self::Annually
80    }
81}