Skip to main content

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