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