datadog_api_client/datadogV1/model/
model_usage_lambda_response.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/// Response containing the number of Lambda functions and sum of the invocations of all Lambda functions
10/// for each hour for a given organization.
11#[non_exhaustive]
12#[skip_serializing_none]
13#[derive(Clone, Debug, PartialEq, Serialize)]
14pub struct UsageLambdaResponse {
15    /// Get hourly usage for Lambda.
16    #[serde(rename = "usage")]
17    pub usage: Option<Vec<crate::datadogV1::model::UsageLambdaHour>>,
18    #[serde(flatten)]
19    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
20    #[serde(skip)]
21    #[serde(default)]
22    pub(crate) _unparsed: bool,
23}
24
25impl UsageLambdaResponse {
26    pub fn new() -> UsageLambdaResponse {
27        UsageLambdaResponse {
28            usage: None,
29            additional_properties: std::collections::BTreeMap::new(),
30            _unparsed: false,
31        }
32    }
33
34    pub fn usage(mut self, value: Vec<crate::datadogV1::model::UsageLambdaHour>) -> Self {
35        self.usage = Some(value);
36        self
37    }
38
39    pub fn additional_properties(
40        mut self,
41        value: std::collections::BTreeMap<String, serde_json::Value>,
42    ) -> Self {
43        self.additional_properties = value;
44        self
45    }
46}
47
48impl Default for UsageLambdaResponse {
49    fn default() -> Self {
50        Self::new()
51    }
52}
53
54impl<'de> Deserialize<'de> for UsageLambdaResponse {
55    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
56    where
57        D: Deserializer<'de>,
58    {
59        struct UsageLambdaResponseVisitor;
60        impl<'a> Visitor<'a> for UsageLambdaResponseVisitor {
61            type Value = UsageLambdaResponse;
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 usage: Option<Vec<crate::datadogV1::model::UsageLambdaHour>> = None;
72                let mut additional_properties: std::collections::BTreeMap<
73                    String,
74                    serde_json::Value,
75                > = std::collections::BTreeMap::new();
76                let mut _unparsed = false;
77
78                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
79                    match k.as_str() {
80                        "usage" => {
81                            if v.is_null() {
82                                continue;
83                            }
84                            usage = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
85                        }
86                        &_ => {
87                            if let Ok(value) = serde_json::from_value(v.clone()) {
88                                additional_properties.insert(k, value);
89                            }
90                        }
91                    }
92                }
93
94                let content = UsageLambdaResponse {
95                    usage,
96                    additional_properties,
97                    _unparsed,
98                };
99
100                Ok(content)
101            }
102        }
103
104        deserializer.deserialize_any(UsageLambdaResponseVisitor)
105    }
106}