datadog_api_client/datadogV2/model/
model_entity_v3_queue_spec.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 Entity V3 Queue Spec object.
10#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct EntityV3QueueSpec {
14    /// A list of components the queue is a part of
15    #[serde(rename = "componentOf")]
16    pub component_of: Option<Vec<String>>,
17    /// The lifecycle state of the queue.
18    #[serde(rename = "lifecycle")]
19    pub lifecycle: Option<String>,
20    /// The importance of the queue.
21    #[serde(rename = "tier")]
22    pub tier: Option<String>,
23    /// The type of queue.
24    #[serde(rename = "type")]
25    pub type_: Option<String>,
26    #[serde(skip)]
27    #[serde(default)]
28    pub(crate) _unparsed: bool,
29}
30
31impl EntityV3QueueSpec {
32    pub fn new() -> EntityV3QueueSpec {
33        EntityV3QueueSpec {
34            component_of: None,
35            lifecycle: None,
36            tier: None,
37            type_: None,
38            _unparsed: false,
39        }
40    }
41
42    pub fn component_of(mut self, value: Vec<String>) -> Self {
43        self.component_of = Some(value);
44        self
45    }
46
47    pub fn lifecycle(mut self, value: String) -> Self {
48        self.lifecycle = Some(value);
49        self
50    }
51
52    pub fn tier(mut self, value: String) -> Self {
53        self.tier = Some(value);
54        self
55    }
56
57    pub fn type_(mut self, value: String) -> Self {
58        self.type_ = Some(value);
59        self
60    }
61}
62
63impl Default for EntityV3QueueSpec {
64    fn default() -> Self {
65        Self::new()
66    }
67}
68
69impl<'de> Deserialize<'de> for EntityV3QueueSpec {
70    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
71    where
72        D: Deserializer<'de>,
73    {
74        struct EntityV3QueueSpecVisitor;
75        impl<'a> Visitor<'a> for EntityV3QueueSpecVisitor {
76            type Value = EntityV3QueueSpec;
77
78            fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
79                f.write_str("a mapping")
80            }
81
82            fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
83            where
84                M: MapAccess<'a>,
85            {
86                let mut component_of: Option<Vec<String>> = None;
87                let mut lifecycle: Option<String> = None;
88                let mut tier: Option<String> = None;
89                let mut type_: Option<String> = None;
90                let mut _unparsed = false;
91
92                while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
93                    match k.as_str() {
94                        "componentOf" => {
95                            if v.is_null() {
96                                continue;
97                            }
98                            component_of =
99                                Some(serde_json::from_value(v).map_err(M::Error::custom)?);
100                        }
101                        "lifecycle" => {
102                            if v.is_null() {
103                                continue;
104                            }
105                            lifecycle = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
106                        }
107                        "tier" => {
108                            if v.is_null() {
109                                continue;
110                            }
111                            tier = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
112                        }
113                        "type" => {
114                            if v.is_null() {
115                                continue;
116                            }
117                            type_ = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
118                        }
119                        &_ => {
120                            return Err(serde::de::Error::custom(
121                                "Additional properties not allowed",
122                            ));
123                        }
124                    }
125                }
126
127                let content = EntityV3QueueSpec {
128                    component_of,
129                    lifecycle,
130                    tier,
131                    type_,
132                    _unparsed,
133                };
134
135                Ok(content)
136            }
137        }
138
139        deserializer.deserialize_any(EntityV3QueueSpecVisitor)
140    }
141}