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