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