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