datadog_api_client/datadogV1/model/
model_synthetics_variable_parser.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 SyntheticsVariableParser {
14 #[serde(rename = "type")]
16 pub type_: crate::datadogV1::model::SyntheticsGlobalVariableParserType,
17 #[serde(rename = "value")]
19 pub value: Option<String>,
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 SyntheticsVariableParser {
28 pub fn new(
29 type_: crate::datadogV1::model::SyntheticsGlobalVariableParserType,
30 ) -> SyntheticsVariableParser {
31 SyntheticsVariableParser {
32 type_,
33 value: None,
34 additional_properties: std::collections::BTreeMap::new(),
35 _unparsed: false,
36 }
37 }
38
39 pub fn value(mut self, value: String) -> Self {
40 self.value = Some(value);
41 self
42 }
43
44 pub fn additional_properties(
45 mut self,
46 value: std::collections::BTreeMap<String, serde_json::Value>,
47 ) -> Self {
48 self.additional_properties = value;
49 self
50 }
51}
52
53impl<'de> Deserialize<'de> for SyntheticsVariableParser {
54 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
55 where
56 D: Deserializer<'de>,
57 {
58 struct SyntheticsVariableParserVisitor;
59 impl<'a> Visitor<'a> for SyntheticsVariableParserVisitor {
60 type Value = SyntheticsVariableParser;
61
62 fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
63 f.write_str("a mapping")
64 }
65
66 fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
67 where
68 M: MapAccess<'a>,
69 {
70 let mut type_: Option<crate::datadogV1::model::SyntheticsGlobalVariableParserType> =
71 None;
72 let mut value: Option<String> = None;
73 let mut additional_properties: std::collections::BTreeMap<
74 String,
75 serde_json::Value,
76 > = std::collections::BTreeMap::new();
77 let mut _unparsed = false;
78
79 while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
80 match k.as_str() {
81 "type" => {
82 type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
83 if let Some(ref _type_) = type_ {
84 match _type_ {
85 crate::datadogV1::model::SyntheticsGlobalVariableParserType::UnparsedObject(_type_) => {
86 _unparsed = true;
87 },
88 _ => {}
89 }
90 }
91 }
92 "value" => {
93 if v.is_null() {
94 continue;
95 }
96 value = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
97 }
98 &_ => {
99 if let Ok(value) = serde_json::from_value(v.clone()) {
100 additional_properties.insert(k, value);
101 }
102 }
103 }
104 }
105 let type_ = type_.ok_or_else(|| M::Error::missing_field("type_"))?;
106
107 let content = SyntheticsVariableParser {
108 type_,
109 value,
110 additional_properties,
111 _unparsed,
112 };
113
114 Ok(content)
115 }
116 }
117
118 deserializer.deserialize_any(SyntheticsVariableParserVisitor)
119 }
120}