k8s_openapi/v1_33/api/resource/v1beta2/
counter_set.rs

1// Generated from definition io.k8s.api.resource.v1beta2.CounterSet
2
3/// CounterSet defines a named set of counters that are available to be used by devices defined in the ResourceSlice.
4///
5/// The counters are not allocatable by themselves, but can be referenced by devices. When a device is allocated, the portion of counters it uses will no longer be available for use by other devices.
6#[derive(Clone, Debug, Default, PartialEq)]
7pub struct CounterSet {
8    /// Counters defines the set of counters for this CounterSet The name of each counter must be unique in that set and must be a DNS label.
9    ///
10    /// The maximum number of counters in all sets is 32.
11    pub counters: std::collections::BTreeMap<std::string::String, crate::api::resource::v1beta2::Counter>,
12
13    /// Name defines the name of the counter set. It must be a DNS label.
14    pub name: std::string::String,
15}
16
17impl crate::DeepMerge for CounterSet {
18    fn merge_from(&mut self, other: Self) {
19        crate::merge_strategies::map::granular(&mut self.counters, other.counters, |current_item, other_item| {
20            crate::DeepMerge::merge_from(current_item, other_item);
21        });
22        crate::DeepMerge::merge_from(&mut self.name, other.name);
23    }
24}
25
26impl<'de> crate::serde::Deserialize<'de> for CounterSet {
27    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
28        #[allow(non_camel_case_types)]
29        enum Field {
30            Key_counters,
31            Key_name,
32            Other,
33        }
34
35        impl<'de> crate::serde::Deserialize<'de> for Field {
36            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
37                struct Visitor;
38
39                impl crate::serde::de::Visitor<'_> for Visitor {
40                    type Value = Field;
41
42                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
43                        f.write_str("field identifier")
44                    }
45
46                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
47                        Ok(match v {
48                            "counters" => Field::Key_counters,
49                            "name" => Field::Key_name,
50                            _ => Field::Other,
51                        })
52                    }
53                }
54
55                deserializer.deserialize_identifier(Visitor)
56            }
57        }
58
59        struct Visitor;
60
61        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
62            type Value = CounterSet;
63
64            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
65                f.write_str("CounterSet")
66            }
67
68            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
69                let mut value_counters: Option<std::collections::BTreeMap<std::string::String, crate::api::resource::v1beta2::Counter>> = None;
70                let mut value_name: Option<std::string::String> = None;
71
72                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
73                    match key {
74                        Field::Key_counters => value_counters = crate::serde::de::MapAccess::next_value(&mut map)?,
75                        Field::Key_name => value_name = crate::serde::de::MapAccess::next_value(&mut map)?,
76                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
77                    }
78                }
79
80                Ok(CounterSet {
81                    counters: value_counters.unwrap_or_default(),
82                    name: value_name.unwrap_or_default(),
83                })
84            }
85        }
86
87        deserializer.deserialize_struct(
88            "CounterSet",
89            &[
90                "counters",
91                "name",
92            ],
93            Visitor,
94        )
95    }
96}
97
98impl crate::serde::Serialize for CounterSet {
99    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
100        let mut state = serializer.serialize_struct(
101            "CounterSet",
102            2,
103        )?;
104        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "counters", &self.counters)?;
105        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "name", &self.name)?;
106        crate::serde::ser::SerializeStruct::end(state)
107    }
108}
109
110#[cfg(feature = "schemars")]
111impl crate::schemars::JsonSchema for CounterSet {
112    fn schema_name() -> std::string::String {
113        "io.k8s.api.resource.v1beta2.CounterSet".into()
114    }
115
116    fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
117        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
118            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
119                description: Some("CounterSet defines a named set of counters that are available to be used by devices defined in the ResourceSlice.\n\nThe counters are not allocatable by themselves, but can be referenced by devices. When a device is allocated, the portion of counters it uses will no longer be available for use by other devices.".into()),
120                ..Default::default()
121            })),
122            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Object))),
123            object: Some(std::boxed::Box::new(crate::schemars::schema::ObjectValidation {
124                properties: [
125                    (
126                        "counters".into(),
127                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
128                            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
129                                description: Some("Counters defines the set of counters for this CounterSet The name of each counter must be unique in that set and must be a DNS label.\n\nThe maximum number of counters in all sets is 32.".into()),
130                                ..Default::default()
131                            })),
132                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::Object))),
133                            object: Some(std::boxed::Box::new(crate::schemars::schema::ObjectValidation {
134                                additional_properties: Some(std::boxed::Box::new(__gen.subschema_for::<crate::api::resource::v1beta2::Counter>())),
135                                ..Default::default()
136                            })),
137                            ..Default::default()
138                        }),
139                    ),
140                    (
141                        "name".into(),
142                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
143                            metadata: Some(std::boxed::Box::new(crate::schemars::schema::Metadata {
144                                description: Some("Name defines the name of the counter set. It must be a DNS label.".into()),
145                                ..Default::default()
146                            })),
147                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(std::boxed::Box::new(crate::schemars::schema::InstanceType::String))),
148                            ..Default::default()
149                        }),
150                    ),
151                ].into(),
152                required: [
153                    "counters".into(),
154                    "name".into(),
155                ].into(),
156                ..Default::default()
157            })),
158            ..Default::default()
159        })
160    }
161}