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