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