Skip to main content

k8s_openapi/v1_37/api/resource/v1beta1/
device_attribute.rs

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