k8s_openapi/v1_31/api/resource/v1alpha3/
basic_device.rs1#[derive(Clone, Debug, Default, PartialEq)]
5pub struct BasicDevice {
6 pub attributes: Option<std::collections::BTreeMap<std::string::String, crate::api::resource::v1alpha3::DeviceAttribute>>,
10
11 pub capacity: Option<std::collections::BTreeMap<std::string::String, crate::apimachinery::pkg::api::resource::Quantity>>,
15}
16
17impl crate::DeepMerge for BasicDevice {
18 fn merge_from(&mut self, other: Self) {
19 crate::merge_strategies::map::granular(&mut self.attributes, other.attributes, |current_item, other_item| {
20 crate::DeepMerge::merge_from(current_item, other_item);
21 });
22 crate::merge_strategies::map::granular(&mut self.capacity, other.capacity, |current_item, other_item| {
23 crate::DeepMerge::merge_from(current_item, other_item);
24 });
25 }
26}
27
28impl<'de> crate::serde::Deserialize<'de> for BasicDevice {
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_attributes,
33 Key_capacity,
34 Other,
35 }
36
37 impl<'de> crate::serde::Deserialize<'de> for Field {
38 fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
39 struct Visitor;
40
41 impl crate::serde::de::Visitor<'_> for Visitor {
42 type Value = Field;
43
44 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
45 f.write_str("field identifier")
46 }
47
48 fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
49 Ok(match v {
50 "attributes" => Field::Key_attributes,
51 "capacity" => Field::Key_capacity,
52 _ => Field::Other,
53 })
54 }
55 }
56
57 deserializer.deserialize_identifier(Visitor)
58 }
59 }
60
61 struct Visitor;
62
63 impl<'de> crate::serde::de::Visitor<'de> for Visitor {
64 type Value = BasicDevice;
65
66 fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
67 f.write_str("BasicDevice")
68 }
69
70 fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
71 let mut value_attributes: Option<std::collections::BTreeMap<std::string::String, crate::api::resource::v1alpha3::DeviceAttribute>> = None;
72 let mut value_capacity: Option<std::collections::BTreeMap<std::string::String, crate::apimachinery::pkg::api::resource::Quantity>> = None;
73
74 while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
75 match key {
76 Field::Key_attributes => value_attributes = crate::serde::de::MapAccess::next_value(&mut map)?,
77 Field::Key_capacity => value_capacity = crate::serde::de::MapAccess::next_value(&mut map)?,
78 Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
79 }
80 }
81
82 Ok(BasicDevice {
83 attributes: value_attributes,
84 capacity: value_capacity,
85 })
86 }
87 }
88
89 deserializer.deserialize_struct(
90 "BasicDevice",
91 &[
92 "attributes",
93 "capacity",
94 ],
95 Visitor,
96 )
97 }
98}
99
100impl crate::serde::Serialize for BasicDevice {
101 fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
102 let mut state = serializer.serialize_struct(
103 "BasicDevice",
104 self.attributes.as_ref().map_or(0, |_| 1) +
105 self.capacity.as_ref().map_or(0, |_| 1),
106 )?;
107 if let Some(value) = &self.attributes {
108 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "attributes", value)?;
109 }
110 if let Some(value) = &self.capacity {
111 crate::serde::ser::SerializeStruct::serialize_field(&mut state, "capacity", value)?;
112 }
113 crate::serde::ser::SerializeStruct::end(state)
114 }
115}
116
117#[cfg(feature = "schemars")]
118impl crate::schemars::JsonSchema for BasicDevice {
119 fn schema_name() -> std::borrow::Cow<'static, str> {
120 "io.k8s.api.resource.v1alpha3.BasicDevice".into()
121 }
122
123 fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
124 crate::schemars::json_schema!({
125 "description": "BasicDevice defines one device instance.",
126 "type": "object",
127 "properties": {
128 "attributes": {
129 "description": "Attributes defines the set of attributes for this device. The name of each attribute must be unique in that set.\n\nThe maximum number of attributes and capacities combined is 32.",
130 "type": "object",
131 "additionalProperties": (__gen.subschema_for::<crate::api::resource::v1alpha3::DeviceAttribute>()),
132 },
133 "capacity": {
134 "description": "Capacity defines the set of capacities for this device. The name of each capacity must be unique in that set.\n\nThe maximum number of attributes and capacities combined is 32.",
135 "type": "object",
136 "additionalProperties": (__gen.subschema_for::<crate::apimachinery::pkg::api::resource::Quantity>()),
137 },
138 },
139 })
140 }
141}