datadog_api_client/datadogV2/model/
model_custom_destination_update_request_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 CustomDestinationUpdateRequestAttributes {
14 #[serde(rename = "enabled")]
16 pub enabled: Option<bool>,
17 #[serde(rename = "forward_tags")]
19 pub forward_tags: Option<bool>,
20 #[serde(rename = "forward_tags_restriction_list")]
23 pub forward_tags_restriction_list: Option<Vec<String>>,
24 #[serde(rename = "forward_tags_restriction_list_type")]
30 pub forward_tags_restriction_list_type:
31 Option<crate::datadogV2::model::CustomDestinationAttributeTagsRestrictionListType>,
32 #[serde(rename = "forwarder_destination")]
34 pub forwarder_destination: Option<crate::datadogV2::model::CustomDestinationForwardDestination>,
35 #[serde(rename = "name")]
37 pub name: Option<String>,
38 #[serde(rename = "query")]
40 pub query: Option<String>,
41 #[serde(flatten)]
42 pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
43 #[serde(skip)]
44 #[serde(default)]
45 pub(crate) _unparsed: bool,
46}
47
48impl CustomDestinationUpdateRequestAttributes {
49 pub fn new() -> CustomDestinationUpdateRequestAttributes {
50 CustomDestinationUpdateRequestAttributes {
51 enabled: None,
52 forward_tags: None,
53 forward_tags_restriction_list: None,
54 forward_tags_restriction_list_type: None,
55 forwarder_destination: None,
56 name: None,
57 query: None,
58 additional_properties: std::collections::BTreeMap::new(),
59 _unparsed: false,
60 }
61 }
62
63 pub fn enabled(mut self, value: bool) -> Self {
64 self.enabled = Some(value);
65 self
66 }
67
68 pub fn forward_tags(mut self, value: bool) -> Self {
69 self.forward_tags = Some(value);
70 self
71 }
72
73 pub fn forward_tags_restriction_list(mut self, value: Vec<String>) -> Self {
74 self.forward_tags_restriction_list = Some(value);
75 self
76 }
77
78 pub fn forward_tags_restriction_list_type(
79 mut self,
80 value: crate::datadogV2::model::CustomDestinationAttributeTagsRestrictionListType,
81 ) -> Self {
82 self.forward_tags_restriction_list_type = Some(value);
83 self
84 }
85
86 pub fn forwarder_destination(
87 mut self,
88 value: crate::datadogV2::model::CustomDestinationForwardDestination,
89 ) -> Self {
90 self.forwarder_destination = Some(value);
91 self
92 }
93
94 pub fn name(mut self, value: String) -> Self {
95 self.name = Some(value);
96 self
97 }
98
99 pub fn query(mut self, value: String) -> Self {
100 self.query = Some(value);
101 self
102 }
103
104 pub fn additional_properties(
105 mut self,
106 value: std::collections::BTreeMap<String, serde_json::Value>,
107 ) -> Self {
108 self.additional_properties = value;
109 self
110 }
111}
112
113impl Default for CustomDestinationUpdateRequestAttributes {
114 fn default() -> Self {
115 Self::new()
116 }
117}
118
119impl<'de> Deserialize<'de> for CustomDestinationUpdateRequestAttributes {
120 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
121 where
122 D: Deserializer<'de>,
123 {
124 struct CustomDestinationUpdateRequestAttributesVisitor;
125 impl<'a> Visitor<'a> for CustomDestinationUpdateRequestAttributesVisitor {
126 type Value = CustomDestinationUpdateRequestAttributes;
127
128 fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
129 f.write_str("a mapping")
130 }
131
132 fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
133 where
134 M: MapAccess<'a>,
135 {
136 let mut enabled: Option<bool> = None;
137 let mut forward_tags: Option<bool> = None;
138 let mut forward_tags_restriction_list: Option<Vec<String>> = None;
139 let mut forward_tags_restriction_list_type: Option<
140 crate::datadogV2::model::CustomDestinationAttributeTagsRestrictionListType,
141 > = None;
142 let mut forwarder_destination: Option<
143 crate::datadogV2::model::CustomDestinationForwardDestination,
144 > = None;
145 let mut name: Option<String> = None;
146 let mut query: Option<String> = None;
147 let mut additional_properties: std::collections::BTreeMap<
148 String,
149 serde_json::Value,
150 > = std::collections::BTreeMap::new();
151 let mut _unparsed = false;
152
153 while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
154 match k.as_str() {
155 "enabled" => {
156 if v.is_null() {
157 continue;
158 }
159 enabled = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
160 }
161 "forward_tags" => {
162 if v.is_null() {
163 continue;
164 }
165 forward_tags =
166 Some(serde_json::from_value(v).map_err(M::Error::custom)?);
167 }
168 "forward_tags_restriction_list" => {
169 if v.is_null() {
170 continue;
171 }
172 forward_tags_restriction_list =
173 Some(serde_json::from_value(v).map_err(M::Error::custom)?);
174 }
175 "forward_tags_restriction_list_type" => {
176 if v.is_null() {
177 continue;
178 }
179 forward_tags_restriction_list_type =
180 Some(serde_json::from_value(v).map_err(M::Error::custom)?);
181 if let Some(ref _forward_tags_restriction_list_type) =
182 forward_tags_restriction_list_type
183 {
184 match _forward_tags_restriction_list_type {
185 crate::datadogV2::model::CustomDestinationAttributeTagsRestrictionListType::UnparsedObject(_forward_tags_restriction_list_type) => {
186 _unparsed = true;
187 },
188 _ => {}
189 }
190 }
191 }
192 "forwarder_destination" => {
193 if v.is_null() {
194 continue;
195 }
196 forwarder_destination =
197 Some(serde_json::from_value(v).map_err(M::Error::custom)?);
198 if let Some(ref _forwarder_destination) = forwarder_destination {
199 match _forwarder_destination {
200 crate::datadogV2::model::CustomDestinationForwardDestination::UnparsedObject(_forwarder_destination) => {
201 _unparsed = true;
202 },
203 _ => {}
204 }
205 }
206 }
207 "name" => {
208 if v.is_null() {
209 continue;
210 }
211 name = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
212 }
213 "query" => {
214 if v.is_null() {
215 continue;
216 }
217 query = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
218 }
219 &_ => {
220 if let Ok(value) = serde_json::from_value(v.clone()) {
221 additional_properties.insert(k, value);
222 }
223 }
224 }
225 }
226
227 let content = CustomDestinationUpdateRequestAttributes {
228 enabled,
229 forward_tags,
230 forward_tags_restriction_list,
231 forward_tags_restriction_list_type,
232 forwarder_destination,
233 name,
234 query,
235 additional_properties,
236 _unparsed,
237 };
238
239 Ok(content)
240 }
241 }
242
243 deserializer.deserialize_any(CustomDestinationUpdateRequestAttributesVisitor)
244 }
245}