datadog_api_client/datadogV1/model/
model_creator.rs1use serde::de::{Error, MapAccess, Visitor};
5use serde::{Deserialize, Deserializer, Serialize};
6use serde_with::skip_serializing_none;
7use std::fmt::{self, Formatter};
8
9#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct Creator {
14 #[serde(rename = "email")]
16 pub email: Option<String>,
17 #[serde(rename = "handle")]
19 pub handle: Option<String>,
20 #[serde(rename = "name", default, with = "::serde_with::rust::double_option")]
22 pub name: Option<Option<String>>,
23 #[serde(flatten)]
24 pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
25 #[serde(skip)]
26 #[serde(default)]
27 pub(crate) _unparsed: bool,
28}
29
30impl Creator {
31 pub fn new() -> Creator {
32 Creator {
33 email: None,
34 handle: None,
35 name: None,
36 additional_properties: std::collections::BTreeMap::new(),
37 _unparsed: false,
38 }
39 }
40
41 pub fn email(mut self, value: String) -> Self {
42 self.email = Some(value);
43 self
44 }
45
46 pub fn handle(mut self, value: String) -> Self {
47 self.handle = Some(value);
48 self
49 }
50
51 pub fn name(mut self, value: Option<String>) -> Self {
52 self.name = Some(value);
53 self
54 }
55
56 pub fn additional_properties(
57 mut self,
58 value: std::collections::BTreeMap<String, serde_json::Value>,
59 ) -> Self {
60 self.additional_properties = value;
61 self
62 }
63}
64
65impl Default for Creator {
66 fn default() -> Self {
67 Self::new()
68 }
69}
70
71impl<'de> Deserialize<'de> for Creator {
72 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
73 where
74 D: Deserializer<'de>,
75 {
76 struct CreatorVisitor;
77 impl<'a> Visitor<'a> for CreatorVisitor {
78 type Value = Creator;
79
80 fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
81 f.write_str("a mapping")
82 }
83
84 fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
85 where
86 M: MapAccess<'a>,
87 {
88 let mut email: Option<String> = None;
89 let mut handle: Option<String> = None;
90 let mut name: Option<Option<String>> = None;
91 let mut additional_properties: std::collections::BTreeMap<
92 String,
93 serde_json::Value,
94 > = std::collections::BTreeMap::new();
95 let mut _unparsed = false;
96
97 while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
98 match k.as_str() {
99 "email" => {
100 if v.is_null() {
101 continue;
102 }
103 email = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
104 }
105 "handle" => {
106 if v.is_null() {
107 continue;
108 }
109 handle = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
110 }
111 "name" => {
112 name = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
113 }
114 &_ => {
115 if let Ok(value) = serde_json::from_value(v.clone()) {
116 additional_properties.insert(k, value);
117 }
118 }
119 }
120 }
121
122 let content = Creator {
123 email,
124 handle,
125 name,
126 additional_properties,
127 _unparsed,
128 };
129
130 Ok(content)
131 }
132 }
133
134 deserializer.deserialize_any(CreatorVisitor)
135 }
136}