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