datadog_api_client/datadogV2/model/
model_custom_destination_update_request.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 custom destination.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct CustomDestinationUpdateRequest {
14    /// The definition of a custom destination.
15    #[serde(rename = "data")]
16    pub data: Option<crate::datadogV2::model::CustomDestinationUpdateRequestDefinition>,
17    #[serde(flatten)]
18    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
19    #[serde(skip)]
20    #[serde(default)]
21    pub(crate) _unparsed: bool,
22}
23
24impl CustomDestinationUpdateRequest {
25    pub fn new() -> CustomDestinationUpdateRequest {
26        CustomDestinationUpdateRequest {
27            data: None,
28            additional_properties: std::collections::BTreeMap::new(),
29            _unparsed: false,
30        }
31    }
32
33    pub fn data(
34        mut self,
35        value: crate::datadogV2::model::CustomDestinationUpdateRequestDefinition,
36    ) -> Self {
37        self.data = Some(value);
38        self
39    }
40
41    pub fn additional_properties(
42        mut self,
43        value: std::collections::BTreeMap<String, serde_json::Value>,
44    ) -> Self {
45        self.additional_properties = value;
46        self
47    }
48}
49
50impl Default for CustomDestinationUpdateRequest {
51    fn default() -> Self {
52        Self::new()
53    }
54}
55
56impl<'de> Deserialize<'de> for CustomDestinationUpdateRequest {
57    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
58    where
59        D: Deserializer<'de>,
60    {
61        struct CustomDestinationUpdateRequestVisitor;
62        impl<'a> Visitor<'a> for CustomDestinationUpdateRequestVisitor {
63            type Value = CustomDestinationUpdateRequest;
64
65            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
66                f.write_str("a mapping")
67            }
68
69            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
70            where
71                M: MapAccess<'a>,
72            {
73                let mut data: Option<
74                    crate::datadogV2::model::CustomDestinationUpdateRequestDefinition,
75                > = None;
76                let mut additional_properties: std::collections::BTreeMap<
77                    String,
78                    serde_json::Value,
79                > = std::collections::BTreeMap::new();
80                let mut _unparsed = false;
81
82                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
83                    match k.as_str() {
84                        "data" => {
85                            if v.is_null() {
86                                continue;
87                            }
88                            data = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
89                        }
90                        &_ => {
91                            if let Ok(value) = serde_json::from_value(v.clone()) {
92                                additional_properties.insert(k, value);
93                            }
94                        }
95                    }
96                }
97
98                let content = CustomDestinationUpdateRequest {
99                    data,
100                    additional_properties,
101                    _unparsed,
102                };
103
104                Ok(content)
105            }
106        }
107
108        deserializer.deserialize_any(CustomDestinationUpdateRequestVisitor)
109    }
110}