k8s_openapi/v1_34/api/resource/v1/
device_attribute.rs1#[derive(Clone, Debug, Default, PartialEq)]
5pub struct DeviceAttribute {
6 pub bool: Option<bool>,
8
9 pub int: Option<i64>,
11
12 pub string: Option<std::string::String>,
14
15 pub version: Option<std::string::String>,
17}
18
19impl crate::DeepMerge for DeviceAttribute {
20 fn merge_from(&mut self, other: Self) {
21 crate::DeepMerge::merge_from(&mut self.bool, other.bool);
22 crate::DeepMerge::merge_from(&mut self.int, other.int);
23 crate::DeepMerge::merge_from(&mut self.string, other.string);
24 crate::DeepMerge::merge_from(&mut self.version, other.version);
25 }
26}
27
28impl<'de> crate::serde::Deserialize<'de> for DeviceAttribute {
29 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
30 #[allow(non_camel_case_types)]
31 enum Field {
32 Key_bool,
33 Key_int,
34 Key_string,
35 Key_version,
36 Other,
37 }
38
39 impl<'de> crate::serde::Deserialize<'de> for Field {
40 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
41 struct Visitor;
42
43 impl crate::serde::de::Visitor<'_> for Visitor {
44 type Value = Field;
45
46 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
47 f.write_str("field identifier")
48 }
49
50 fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
51 Ok(match v {
52 "bool" => Field::Key_bool,
53 "int" => Field::Key_int,
54 "string" => Field::Key_string,
55 "version" => Field::Key_version,
56 _ => Field::Other,
57 })
58 }
59 }
60
61 deserializer.deserialize_identifier(Visitor)
62 }
63 }
64
65 struct Visitor;
66
67 impl<'de> crate::serde::de::Visitor<'de> for Visitor {
68 type Value = DeviceAttribute;
69
70 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
71 f.write_str("DeviceAttribute")
72 }
73
74 fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
75 let mut value_bool: Option<bool> = None;
76 let mut value_int: Option<i64> = None;
77 let mut value_string: Option<std::string::String> = None;
78 let mut value_version: Option<std::string::String> = None;
79
80 while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
81 match key {
82 Field::Key_bool => value_bool = crate::serde::de::MapAccess::next_value(&mut map)?,
83 Field::Key_int => value_int = crate::serde::de::MapAccess::next_value(&mut map)?,
84 Field::Key_string => value_string = crate::serde::de::MapAccess::next_value(&mut map)?,
85 Field::Key_version => value_version = crate::serde::de::MapAccess::next_value(&mut map)?,
86 Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
87 }
88 }
89
90 Ok(DeviceAttribute {
91 bool: value_bool,
92 int: value_int,
93 string: value_string,
94 version: value_version,
95 })
96 }
97 }
98
99 deserializer.deserialize_struct(
100 "DeviceAttribute",
101 &[
102 "bool",
103 "int",
104 "string",
105 "version",
106 ],
107 Visitor,
108 )
109 }
110}
111
112impl crate::serde::Serialize for DeviceAttribute {
113 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
114 let mut state = serializer.serialize_struct(
115 "DeviceAttribute",
116 self.bool.as_ref().map_or(0, |_| 1) +
117 self.int.as_ref().map_or(0, |_| 1) +
118 self.string.as_ref().map_or(0, |_| 1) +
119 self.version.as_ref().map_or(0, |_| 1),
120 )?;
121 if let Some(value) = &self.bool {
122 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "bool", value)?;
123 }
124 if let Some(value) = &self.int {
125 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "int", value)?;
126 }
127 if let Some(value) = &self.string {
128 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "string", value)?;
129 }
130 if let Some(value) = &self.version {
131 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "version", value)?;
132 }
133 crate::serde::ser::SerializeStruct::end(state)
134 }
135}
136
137#[cfg(feature = "schemars")]
138impl crate::schemars::JsonSchema for DeviceAttribute {
139 fn schema_name() -> std::borrow::Cow<'static, str> {
140 "io.k8s.api.resource.v1.DeviceAttribute".into()
141 }
142
143 fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
144 crate::schemars::json_schema!({
145 "description": "DeviceAttribute must have exactly one field set.",
146 "type": "object",
147 "properties": {
148 "bool": {
149 "description": "BoolValue is a true/false value.",
150 "type": "boolean",
151 },
152 "int": {
153 "description": "IntValue is a number.",
154 "type": "integer",
155 "format": "int64",
156 },
157 "string": {
158 "description": "StringValue is a string. Must not be longer than 64 characters.",
159 "type": "string",
160 },
161 "version": {
162 "description": "VersionValue is a semantic version according to semver.org spec 2.0.0. Must not be longer than 64 characters.",
163 "type": "string",
164 },
165 },
166 })
167 }
168}
169
170#[cfg(feature = "schemars08")]
171impl crate::schemars08::JsonSchema for DeviceAttribute {
172 fn schema_name() -> std::string::String {
173 "io.k8s.api.resource.v1.DeviceAttribute".into()
174 }
175
176 fn json_schema(__gen: &mut crate::schemars08::gen::SchemaGenerator) -> crate::schemars08::schema::Schema {
177 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
178 metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
179 description: Some("DeviceAttribute must have exactly one field set.".into()),
180 ..Default::default()
181 })),
182 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Object))),
183 object: Some(std::boxed::Box::new(crate::schemars08::schema::ObjectValidation {
184 properties: [
185 (
186 "bool".into(),
187 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
188 metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
189 description: Some("BoolValue is a true/false value.".into()),
190 ..Default::default()
191 })),
192 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Boolean))),
193 ..Default::default()
194 }),
195 ),
196 (
197 "int".into(),
198 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
199 metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
200 description: Some("IntValue is a number.".into()),
201 ..Default::default()
202 })),
203 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::Integer))),
204 format: Some("int64".into()),
205 ..Default::default()
206 }),
207 ),
208 (
209 "string".into(),
210 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
211 metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
212 description: Some("StringValue is a string. Must not be longer than 64 characters.".into()),
213 ..Default::default()
214 })),
215 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
216 ..Default::default()
217 }),
218 ),
219 (
220 "version".into(),
221 crate::schemars08::schema::Schema::Object(crate::schemars08::schema::SchemaObject {
222 metadata: Some(std::boxed::Box::new(crate::schemars08::schema::Metadata {
223 description: Some("VersionValue is a semantic version according to semver.org spec 2.0.0. Must not be longer than 64 characters.".into()),
224 ..Default::default()
225 })),
226 instance_type: Some(crate::schemars08::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars08::schema::InstanceType::String))),
227 ..Default::default()
228 }),
229 ),
230 ].into(),
231 ..Default::default()
232 })),
233 ..Default::default()
234 })
235 }
236}