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