datadog_api_client/datadogV2/model/
model_entity_v3_datadog_performance.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/// Performance stats association.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct EntityV3DatadogPerformance {
14    /// A list of APM entity tags that associates the APM Stats data with the entity.
15    #[serde(rename = "tags")]
16    pub tags: Option<Vec<String>>,
17    #[serde(skip)]
18    #[serde(default)]
19    pub(crate) _unparsed: bool,
20}
21
22impl EntityV3DatadogPerformance {
23    pub fn new() -> EntityV3DatadogPerformance {
24        EntityV3DatadogPerformance {
25            tags: None,
26            _unparsed: false,
27        }
28    }
29
30    pub fn tags(mut self, value: Vec<String>) -> Self {
31        self.tags = Some(value);
32        self
33    }
34}
35
36impl Default for EntityV3DatadogPerformance {
37    fn default() -> Self {
38        Self::new()
39    }
40}
41
42impl<'de> Deserialize<'de> for EntityV3DatadogPerformance {
43    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
44    where
45        D: Deserializer<'de>,
46    {
47        struct EntityV3DatadogPerformanceVisitor;
48        impl<'a> Visitor<'a> for EntityV3DatadogPerformanceVisitor {
49            type Value = EntityV3DatadogPerformance;
50
51            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
52                f.write_str("a mapping")
53            }
54
55            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
56            where
57                M: MapAccess<'a>,
58            {
59                let mut tags: Option<Vec<String>> = None;
60                let mut _unparsed = false;
61
62                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
63                    match k.as_str() {
64                        "tags" => {
65                            if v.is_null() {
66                                continue;
67                            }
68                            tags = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
69                        }
70                        &_ => {
71                            return Err(serde::de::Error::custom(
72                                "Additional properties not allowed",
73                            ));
74                        }
75                    }
76                }
77
78                let content = EntityV3DatadogPerformance { tags, _unparsed };
79
80                Ok(content)
81            }
82        }
83
84        deserializer.deserialize_any(EntityV3DatadogPerformanceVisitor)
85    }
86}