datadog_api_client/datadogV1/model/
model_usage_lambda_hour.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/// 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 UsageLambdaHour {
15    /// Contains the number of different functions for each region and AWS account.
16    #[serde(
17        rename = "func_count",
18        default,
19        with = "::serde_with::rust::double_option"
20    )]
21    pub func_count: Option<Option<i64>>,
22    /// The hour for the usage.
23    #[serde(rename = "hour")]
24    pub hour: Option<chrono::DateTime<chrono::Utc>>,
25    /// Contains the sum of invocations of all functions.
26    #[serde(
27        rename = "invocations_sum",
28        default,
29        with = "::serde_with::rust::double_option"
30    )]
31    pub invocations_sum: Option<Option<i64>>,
32    /// The organization name.
33    #[serde(rename = "org_name")]
34    pub org_name: Option<String>,
35    /// The organization public ID.
36    #[serde(rename = "public_id")]
37    pub public_id: Option<String>,
38    #[serde(flatten)]
39    pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
40    #[serde(skip)]
41    #[serde(default)]
42    pub(crate) _unparsed: bool,
43}
44
45impl UsageLambdaHour {
46    pub fn new() -> UsageLambdaHour {
47        UsageLambdaHour {
48            func_count: None,
49            hour: None,
50            invocations_sum: None,
51            org_name: None,
52            public_id: None,
53            additional_properties: std::collections::BTreeMap::new(),
54            _unparsed: false,
55        }
56    }
57
58    pub fn func_count(mut self, value: Option<i64>) -> Self {
59        self.func_count = Some(value);
60        self
61    }
62
63    pub fn hour(mut self, value: chrono::DateTime<chrono::Utc>) -> Self {
64        self.hour = Some(value);
65        self
66    }
67
68    pub fn invocations_sum(mut self, value: Option<i64>) -> Self {
69        self.invocations_sum = Some(value);
70        self
71    }
72
73    pub fn org_name(mut self, value: String) -> Self {
74        self.org_name = Some(value);
75        self
76    }
77
78    pub fn public_id(mut self, value: String) -> Self {
79        self.public_id = Some(value);
80        self
81    }
82
83    pub fn additional_properties(
84        mut self,
85        value: std::collections::BTreeMap<String, serde_json::Value>,
86    ) -> Self {
87        self.additional_properties = value;
88        self
89    }
90}
91
92impl Default for UsageLambdaHour {
93    fn default() -> Self {
94        Self::new()
95    }
96}
97
98impl<'de> Deserialize<'de> for UsageLambdaHour {
99    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
100    where
101        D: Deserializer<'de>,
102    {
103        struct UsageLambdaHourVisitor;
104        impl<'a> Visitor<'a> for UsageLambdaHourVisitor {
105            type Value = UsageLambdaHour;
106
107            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
108                f.write_str("a mapping")
109            }
110
111            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
112            where
113                M: MapAccess<'a>,
114            {
115                let mut func_count: Option<Option<i64>> = None;
116                let mut hour: Option<chrono::DateTime<chrono::Utc>> = None;
117                let mut invocations_sum: Option<Option<i64>> = None;
118                let mut org_name: Option<String> = None;
119                let mut public_id: Option<String> = None;
120                let mut additional_properties: std::collections::BTreeMap<
121                    String,
122                    serde_json::Value,
123                > = std::collections::BTreeMap::new();
124                let mut _unparsed = false;
125
126                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
127                    match k.as_str() {
128                        "func_count" => {
129                            func_count = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
130                        }
131                        "hour" => {
132                            if v.is_null() {
133                                continue;
134                            }
135                            hour = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
136                        }
137                        "invocations_sum" => {
138                            invocations_sum =
139                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
140                        }
141                        "org_name" => {
142                            if v.is_null() {
143                                continue;
144                            }
145                            org_name = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
146                        }
147                        "public_id" => {
148                            if v.is_null() {
149                                continue;
150                            }
151                            public_id = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
152                        }
153                        &_ => {
154                            if let Ok(value) = serde_json::from_value(v.clone()) {
155                                additional_properties.insert(k, value);
156                            }
157                        }
158                    }
159                }
160
161                let content = UsageLambdaHour {
162                    func_count,
163                    hour,
164                    invocations_sum,
165                    org_name,
166                    public_id,
167                    additional_properties,
168                    _unparsed,
169                };
170
171                Ok(content)
172            }
173        }
174
175        deserializer.deserialize_any(UsageLambdaHourVisitor)
176    }
177}