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