datadog_api_client/datadogV2/model/
model_arbitrary_rule_response_array.rs

1// Unless explicitly stated otherwise all files in this repository are licensed under the Apache-2.0 License.
2// This product includes software developed at Datadog (https://www.datadoghq.com/).
3// Copyright 2019-Present Datadog, Inc.
4use serde::de::{Error, MapAccess, Visitor};
5use serde::{Deserialize, Deserializer, Serialize};
6use serde_with::skip_serializing_none;
7use std::fmt::{self, Formatter};
8
9/// The definition of `ArbitraryRuleResponseArray` object.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct ArbitraryRuleResponseArray {
14    /// The `ArbitraryRuleResponseArray` `data`.
15    #[serde(rename = "data")]
16    pub data: Vec<crate::datadogV2::model::ArbitraryRuleResponseData>,
17    /// The `ArbitraryRuleResponseArray` `meta`.
18    #[serde(rename = "meta")]
19    pub meta: Option<crate::datadogV2::model::ArbitraryRuleResponseArrayMeta>,
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 ArbitraryRuleResponseArray {
28    pub fn new(
29        data: Vec<crate::datadogV2::model::ArbitraryRuleResponseData>,
30    ) -> ArbitraryRuleResponseArray {
31        ArbitraryRuleResponseArray {
32            data,
33            meta: None,
34            additional_properties: std::collections::BTreeMap::new(),
35            _unparsed: false,
36        }
37    }
38
39    pub fn meta(mut self, value: crate::datadogV2::model::ArbitraryRuleResponseArrayMeta) -> Self {
40        self.meta = 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 ArbitraryRuleResponseArray {
54    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
55    where
56        D: Deserializer<'de>,
57    {
58        struct ArbitraryRuleResponseArrayVisitor;
59        impl<'a> Visitor<'a> for ArbitraryRuleResponseArrayVisitor {
60            type Value = ArbitraryRuleResponseArray;
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 data: Option<Vec<crate::datadogV2::model::ArbitraryRuleResponseData>> =
71                    None;
72                let mut meta: Option<crate::datadogV2::model::ArbitraryRuleResponseArrayMeta> =
73                    None;
74                let mut additional_properties: std::collections::BTreeMap<
75                    String,
76                    serde_json::Value,
77                > = std::collections::BTreeMap::new();
78                let mut _unparsed = false;
79
80                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
81                    match k.as_str() {
82                        "data" => {
83                            data = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
84                        }
85                        "meta" => {
86                            if v.is_null() {
87                                continue;
88                            }
89                            meta = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
90                        }
91                        &_ => {
92                            if let Ok(value) = serde_json::from_value(v.clone()) {
93                                additional_properties.insert(k, value);
94                            }
95                        }
96                    }
97                }
98                let data = data.ok_or_else(|| M::Error::missing_field("data"))?;
99
100                let content = ArbitraryRuleResponseArray {
101                    data,
102                    meta,
103                    additional_properties,
104                    _unparsed,
105                };
106
107                Ok(content)
108            }
109        }
110
111        deserializer.deserialize_any(ArbitraryRuleResponseArrayVisitor)
112    }
113}