1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#![allow(
clippy::too_many_arguments,
clippy::large_enum_variant,
clippy::doc_markdown,
)]
pub type AccountId = String;
#[derive(Debug, Clone, PartialEq, Eq)]
pub enum AccountType {
Basic,
Pro,
Business,
}
impl<'de> ::serde::de::Deserialize<'de> for AccountType {
fn deserialize<D: ::serde::de::Deserializer<'de>>(deserializer: D) -> Result<Self, D::Error> {
use serde::de::{self, MapAccess, Visitor};
struct EnumVisitor;
impl<'de> Visitor<'de> for EnumVisitor {
type Value = AccountType;
fn expecting(&self, f: &mut ::std::fmt::Formatter<'_>) -> ::std::fmt::Result {
f.write_str("a AccountType structure")
}
fn visit_map<V: MapAccess<'de>>(self, mut map: V) -> Result<Self::Value, V::Error> {
let tag: &str = match map.next_key()? {
Some(".tag") => map.next_value()?,
_ => return Err(de::Error::missing_field(".tag"))
};
let value = match tag {
"basic" => AccountType::Basic,
"pro" => AccountType::Pro,
"business" => AccountType::Business,
_ => return Err(de::Error::unknown_variant(tag, VARIANTS))
};
crate::eat_json_fields(&mut map)?;
Ok(value)
}
}
const VARIANTS: &[&str] = &["basic",
"pro",
"business"];
deserializer.deserialize_struct("AccountType", VARIANTS, EnumVisitor)
}
}
impl ::serde::ser::Serialize for AccountType {
fn serialize<S: ::serde::ser::Serializer>(&self, serializer: S) -> Result<S::Ok, S::Error> {
use serde::ser::SerializeStruct;
match *self {
AccountType::Basic => {
let mut s = serializer.serialize_struct("AccountType", 1)?;
s.serialize_field(".tag", "basic")?;
s.end()
}
AccountType::Pro => {
let mut s = serializer.serialize_struct("AccountType", 1)?;
s.serialize_field(".tag", "pro")?;
s.end()
}
AccountType::Business => {
let mut s = serializer.serialize_struct("AccountType", 1)?;
s.serialize_field(".tag", "business")?;
s.end()
}
}
}
}