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