Skip to main content

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