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