bitwarden_api_api/models/
collection_type.rs1use serde::{Deserialize, Deserializer, Serialize, Serializer, de::Visitor};
12
13use crate::models;
14#[derive(Clone, Copy, Debug, Eq, PartialEq, Ord, PartialOrd, Hash)]
18pub enum CollectionType {
19 SharedCollection,
20 DefaultUserCollection,
21
22 __Unknown(i64),
24}
25
26impl CollectionType {
27 pub fn as_i64(&self) -> i64 {
28 match self {
29 Self::SharedCollection => 0,
30 Self::DefaultUserCollection => 1,
31 Self::__Unknown(v) => *v,
32 }
33 }
34
35 pub fn from_i64(value: i64) -> Self {
36 match value {
37 0 => Self::SharedCollection,
38 1 => Self::DefaultUserCollection,
39 v => Self::__Unknown(v),
40 }
41 }
42}
43
44impl serde::Serialize for CollectionType {
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 CollectionType {
51 fn deserialize<D: Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
52 struct CollectionTypeVisitor;
53
54 impl Visitor<'_> for CollectionTypeVisitor {
55 type Value = CollectionType;
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(CollectionType::from_i64(v))
63 }
64
65 fn visit_u64<E: serde::de::Error>(self, v: u64) -> Result<Self::Value, E> {
66 Ok(CollectionType::from_i64(v as i64))
67 }
68 }
69
70 deserializer.deserialize_i64(CollectionTypeVisitor)
71 }
72}
73
74impl std::fmt::Display for CollectionType {
75 fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
76 write!(f, "{}", self.as_i64())
77 }
78}
79impl Default for CollectionType {
80 fn default() -> CollectionType {
81 Self::SharedCollection
82 }
83}