datadog_api_client/datadogV2/model/
model_on_demand_concurrency_cap_attributes.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/// On-demand concurrency cap attributes.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct OnDemandConcurrencyCapAttributes {
14    /// Value of the on-demand concurrency cap.
15    #[serde(rename = "on_demand_concurrency_cap")]
16    pub on_demand_concurrency_cap: Option<f64>,
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 OnDemandConcurrencyCapAttributes {
25    pub fn new() -> OnDemandConcurrencyCapAttributes {
26        OnDemandConcurrencyCapAttributes {
27            on_demand_concurrency_cap: None,
28            additional_properties: std::collections::BTreeMap::new(),
29            _unparsed: false,
30        }
31    }
32
33    pub fn on_demand_concurrency_cap(mut self, value: f64) -> Self {
34        self.on_demand_concurrency_cap = Some(value);
35        self
36    }
37
38    pub fn additional_properties(
39        mut self,
40        value: std::collections::BTreeMap<String, serde_json::Value>,
41    ) -> Self {
42        self.additional_properties = value;
43        self
44    }
45}
46
47impl Default for OnDemandConcurrencyCapAttributes {
48    fn default() -> Self {
49        Self::new()
50    }
51}
52
53impl<'de> Deserialize<'de> for OnDemandConcurrencyCapAttributes {
54    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
55    where
56        D: Deserializer<'de>,
57    {
58        struct OnDemandConcurrencyCapAttributesVisitor;
59        impl<'a> Visitor<'a> for OnDemandConcurrencyCapAttributesVisitor {
60            type Value = OnDemandConcurrencyCapAttributes;
61
62            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
63                f.write_str("a mapping")
64            }
65
66            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
67            where
68                M: MapAccess<'a>,
69            {
70                let mut on_demand_concurrency_cap: Option<f64> = None;
71                let mut additional_properties: std::collections::BTreeMap<
72                    String,
73                    serde_json::Value,
74                > = std::collections::BTreeMap::new();
75                let mut _unparsed = false;
76
77                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
78                    match k.as_str() {
79                        "on_demand_concurrency_cap" => {
80                            if v.is_null() {
81                                continue;
82                            }
83                            on_demand_concurrency_cap =
84                                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 = OnDemandConcurrencyCapAttributes {
95                    on_demand_concurrency_cap,
96                    additional_properties,
97                    _unparsed,
98                };
99
100                Ok(content)
101            }
102        }
103
104        deserializer.deserialize_any(OnDemandConcurrencyCapAttributesVisitor)
105    }
106}