bitwarden_api_api/models/
integration_type.rs1use serde::{Deserialize, Deserializer, Serialize, Serializer, de::Visitor};
12
13use crate::models;
14#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
16pub enum IntegrationType {
17 CloudBillingSync,
18 Scim,
19 Slack,
20 Webhook,
21 Hec,
22 Datadog,
23 Teams,
24
25 __Unknown(i64),
27}
28
29impl IntegrationType {
30 pub fn as_i64(&self) -> i64 {
31 match self {
32 Self::CloudBillingSync => 1,
33 Self::Scim => 2,
34 Self::Slack => 3,
35 Self::Webhook => 4,
36 Self::Hec => 5,
37 Self::Datadog => 6,
38 Self::Teams => 7,
39 Self::__Unknown(v) => *v,
40 }
41 }
42
43 pub fn from_i64(value: i64) -> Self {
44 match value {
45 1 => Self::CloudBillingSync,
46 2 => Self::Scim,
47 3 => Self::Slack,
48 4 => Self::Webhook,
49 5 => Self::Hec,
50 6 => Self::Datadog,
51 7 => Self::Teams,
52 v => Self::__Unknown(v),
53 }
54 }
55}
56
57impl serde::Serialize for IntegrationType {
58 fn serialize<S: Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
59 serializer.serialize_i64(self.as_i64())
60 }
61}
62
63impl<'de> serde::Deserialize<'de> for IntegrationType {
64 fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
65 struct IntegrationTypeVisitor;
66
67 impl Visitor<'_> for IntegrationTypeVisitor {
68 type Value = IntegrationType;
69
70 fn expecting(&self, f: &mut std::fmt::Formatter) -> std::fmt::Result {
71 f.write_str("an integer")
72 }
73
74 fn visit_i64<E: serde::de::Error>(self, v: i64) -> Result<Self::Value, E> {
75 Ok(IntegrationType::from_i64(v))
76 }
77
78 fn visit_u64<E: serde::de::Error>(self, v: u64) -> Result<Self::Value, E> {
79 Ok(IntegrationType::from_i64(v as i64))
80 }
81 }
82
83 deserializer.deserialize_i64(IntegrationTypeVisitor)
84 }
85}
86
87impl std::fmt::Display for IntegrationType {
88 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
89 write!(f, "{}", self.as_i64())
90 }
91}
92impl Default for IntegrationType {
93 fn default() -> IntegrationType {
94 Self::CloudBillingSync
95 }
96}