datadog_api_client/datadogV2/model/
model_scalar_meta.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 ScalarMeta {
14 #[serde(rename = "unit", default, with = "::serde_with::rust::double_option")]
19 pub unit: Option<Option<Vec<Option<crate::datadogV2::model::Unit>>>>,
20 #[serde(flatten)]
21 pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
22 #[serde(skip)]
23 #[serde(default)]
24 pub(crate) _unparsed: bool,
25}
26
27impl ScalarMeta {
28 pub fn new() -> ScalarMeta {
29 ScalarMeta {
30 unit: None,
31 additional_properties: std::collections::BTreeMap::new(),
32 _unparsed: false,
33 }
34 }
35
36 pub fn unit(mut self, value: Option<Vec<Option<crate::datadogV2::model::Unit>>>) -> Self {
37 self.unit = Some(value);
38 self
39 }
40
41 pub fn additional_properties(
42 mut self,
43 value: std::collections::BTreeMap<String, serde_json::Value>,
44 ) -> Self {
45 self.additional_properties = value;
46 self
47 }
48}
49
50impl Default for ScalarMeta {
51 fn default() -> Self {
52 Self::new()
53 }
54}
55
56impl<'de> Deserialize<'de> for ScalarMeta {
57 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
58 where
59 D: Deserializer<'de>,
60 {
61 struct ScalarMetaVisitor;
62 impl<'a> Visitor<'a> for ScalarMetaVisitor {
63 type Value = ScalarMeta;
64
65 fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
66 f.write_str("a mapping")
67 }
68
69 fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
70 where
71 M: MapAccess<'a>,
72 {
73 let mut unit: Option<Option<Vec<Option<crate::datadogV2::model::Unit>>>> = None;
74 let mut additional_properties: std::collections::BTreeMap<
75 String,
76 serde_json::Value,
77 > = std::collections::BTreeMap::new();
78 let mut _unparsed = false;
79
80 while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
81 match k.as_str() {
82 "unit" => {
83 unit = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
84 }
85 &_ => {
86 if let Ok(value) = serde_json::from_value(v.clone()) {
87 additional_properties.insert(k, value);
88 }
89 }
90 }
91 }
92
93 let content = ScalarMeta {
94 unit,
95 additional_properties,
96 _unparsed,
97 };
98
99 Ok(content)
100 }
101 }
102
103 deserializer.deserialize_any(ScalarMetaVisitor)
104 }
105}