datadog_api_client/datadogV2/model/
model_user.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 User {
14 #[serde(rename = "attributes")]
16 pub attributes: Option<crate::datadogV2::model::UserAttributes>,
17 #[serde(rename = "id")]
19 pub id: Option<String>,
20 #[serde(rename = "relationships")]
22 pub relationships: Option<crate::datadogV2::model::UserResponseRelationships>,
23 #[serde(rename = "type")]
25 pub type_: Option<crate::datadogV2::model::UsersType>,
26 #[serde(flatten)]
27 pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
28 #[serde(skip)]
29 #[serde(default)]
30 pub(crate) _unparsed: bool,
31}
32
33impl User {
34 pub fn new() -> User {
35 User {
36 attributes: None,
37 id: None,
38 relationships: None,
39 type_: None,
40 additional_properties: std::collections::BTreeMap::new(),
41 _unparsed: false,
42 }
43 }
44
45 pub fn attributes(mut self, value: crate::datadogV2::model::UserAttributes) -> Self {
46 self.attributes = Some(value);
47 self
48 }
49
50 pub fn id(mut self, value: String) -> Self {
51 self.id = Some(value);
52 self
53 }
54
55 pub fn relationships(
56 mut self,
57 value: crate::datadogV2::model::UserResponseRelationships,
58 ) -> Self {
59 self.relationships = Some(value);
60 self
61 }
62
63 pub fn type_(mut self, value: crate::datadogV2::model::UsersType) -> Self {
64 self.type_ = Some(value);
65 self
66 }
67
68 pub fn additional_properties(
69 mut self,
70 value: std::collections::BTreeMap<String, serde_json::Value>,
71 ) -> Self {
72 self.additional_properties = value;
73 self
74 }
75}
76
77impl Default for User {
78 fn default() -> Self {
79 Self::new()
80 }
81}
82
83impl<'de> Deserialize<'de> for User {
84 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
85 where
86 D: Deserializer<'de>,
87 {
88 struct UserVisitor;
89 impl<'a> Visitor<'a> for UserVisitor {
90 type Value = User;
91
92 fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
93 f.write_str("a mapping")
94 }
95
96 fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
97 where
98 M: MapAccess<'a>,
99 {
100 let mut attributes: Option<crate::datadogV2::model::UserAttributes> = None;
101 let mut id: Option<String> = None;
102 let mut relationships: Option<crate::datadogV2::model::UserResponseRelationships> =
103 None;
104 let mut type_: Option<crate::datadogV2::model::UsersType> = None;
105 let mut additional_properties: std::collections::BTreeMap<
106 String,
107 serde_json::Value,
108 > = std::collections::BTreeMap::new();
109 let mut _unparsed = false;
110
111 while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
112 match k.as_str() {
113 "attributes" => {
114 if v.is_null() {
115 continue;
116 }
117 attributes = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
118 }
119 "id" => {
120 if v.is_null() {
121 continue;
122 }
123 id = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
124 }
125 "relationships" => {
126 if v.is_null() {
127 continue;
128 }
129 relationships =
130 Some(serde_json::from_value(v).map_err(M::Error::custom)?);
131 }
132 "type" => {
133 if v.is_null() {
134 continue;
135 }
136 type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
137 if let Some(ref _type_) = type_ {
138 match _type_ {
139 crate::datadogV2::model::UsersType::UnparsedObject(_type_) => {
140 _unparsed = true;
141 }
142 _ => {}
143 }
144 }
145 }
146 &_ => {
147 if let Ok(value) = serde_json::from_value(v.clone()) {
148 additional_properties.insert(k, value);
149 }
150 }
151 }
152 }
153
154 let content = User {
155 attributes,
156 id,
157 relationships,
158 type_,
159 additional_properties,
160 _unparsed,
161 };
162
163 Ok(content)
164 }
165 }
166
167 deserializer.deserialize_any(UserVisitor)
168 }
169}