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