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