datadog_api_client/datadogV2/model/
model_partial_application_key_attributes.rs1use serde::de::{Error, MapAccess, Visitor};
5use serde::{Deserialize, Deserializer, Serialize};
6use serde_with::skip_serializing_none;
7use std::fmt::{self, Formatter};
8
9#[non_exhaustive]
11#[skip_serializing_none]
12#[derive(Clone, Debug, PartialEq, Serialize)]
13pub struct PartialApplicationKeyAttributes {
14 #[serde(rename = "created_at")]
16 pub created_at: Option<String>,
17 #[serde(rename = "last4")]
19 pub last4: Option<String>,
20 #[serde(
22 rename = "last_used_at",
23 default,
24 with = "::serde_with::rust::double_option"
25 )]
26 pub last_used_at: Option<Option<String>>,
27 #[serde(rename = "name")]
29 pub name: Option<String>,
30 #[serde(rename = "scopes", default, with = "::serde_with::rust::double_option")]
32 pub scopes: Option<Option<Vec<String>>>,
33 #[serde(flatten)]
34 pub additional_properties: std::collections::BTreeMap<String, serde_json::Value>,
35 #[serde(skip)]
36 #[serde(default)]
37 pub(crate) _unparsed: bool,
38}
39
40impl PartialApplicationKeyAttributes {
41 pub fn new() -> PartialApplicationKeyAttributes {
42 PartialApplicationKeyAttributes {
43 created_at: None,
44 last4: None,
45 last_used_at: None,
46 name: None,
47 scopes: None,
48 additional_properties: std::collections::BTreeMap::new(),
49 _unparsed: false,
50 }
51 }
52
53 pub fn created_at(mut self, value: String) -> Self {
54 self.created_at = Some(value);
55 self
56 }
57
58 pub fn last4(mut self, value: String) -> Self {
59 self.last4 = Some(value);
60 self
61 }
62
63 pub fn last_used_at(mut self, value: Option<String>) -> Self {
64 self.last_used_at = Some(value);
65 self
66 }
67
68 pub fn name(mut self, value: String) -> Self {
69 self.name = Some(value);
70 self
71 }
72
73 pub fn scopes(mut self, value: Option<Vec<String>>) -> Self {
74 self.scopes = Some(value);
75 self
76 }
77
78 pub fn additional_properties(
79 mut self,
80 value: std::collections::BTreeMap<String, serde_json::Value>,
81 ) -> Self {
82 self.additional_properties = value;
83 self
84 }
85}
86
87impl Default for PartialApplicationKeyAttributes {
88 fn default() -> Self {
89 Self::new()
90 }
91}
92
93impl<'de> Deserialize<'de> for PartialApplicationKeyAttributes {
94 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
95 where
96 D: Deserializer<'de>,
97 {
98 struct PartialApplicationKeyAttributesVisitor;
99 impl<'a> Visitor<'a> for PartialApplicationKeyAttributesVisitor {
100 type Value = PartialApplicationKeyAttributes;
101
102 fn expecting(&self, f: &mut Formatter<'_>) -> fmt::Result {
103 f.write_str("a mapping")
104 }
105
106 fn visit_map<M>(self, mut map: M) -> Result<Self::Value, M::Error>
107 where
108 M: MapAccess<'a>,
109 {
110 let mut created_at: Option<String> = None;
111 let mut last4: Option<String> = None;
112 let mut last_used_at: Option<Option<String>> = None;
113 let mut name: Option<String> = None;
114 let mut scopes: Option<Option<Vec<String>>> = None;
115 let mut additional_properties: std::collections::BTreeMap<
116 String,
117 serde_json::Value,
118 > = std::collections::BTreeMap::new();
119 let mut _unparsed = false;
120
121 while let Some((k, v)) = map.next_entry::<String, serde_json::Value>()? {
122 match k.as_str() {
123 "created_at" => {
124 if v.is_null() {
125 continue;
126 }
127 created_at = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
128 }
129 "last4" => {
130 if v.is_null() {
131 continue;
132 }
133 last4 = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
134 }
135 "last_used_at" => {
136 last_used_at =
137 Some(serde_json::from_value(v).map_err(M::Error::custom)?);
138 }
139 "name" => {
140 if v.is_null() {
141 continue;
142 }
143 name = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
144 }
145 "scopes" => {
146 scopes = Some(serde_json::from_value(v).map_err(M::Error::custom)?);
147 }
148 &_ => {
149 if let Ok(value) = serde_json::from_value(v.clone()) {
150 additional_properties.insert(k, value);
151 }
152 }
153 }
154 }
155
156 let content = PartialApplicationKeyAttributes {
157 created_at,
158 last4,
159 last_used_at,
160 name,
161 scopes,
162 additional_properties,
163 _unparsed,
164 };
165
166 Ok(content)
167 }
168 }
169
170 deserializer.deserialize_any(PartialApplicationKeyAttributesVisitor)
171 }
172}