k8s_openapi/v1_34/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::borrow::Cow<'static, str> {
113        "io.k8s.api.resource.v1beta2.CounterSet".into()
114    }
115
116    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
117        crate::schemars::json_schema!({
118            "description": "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.",
119            "type": "object",
120            "properties": {
121                "counters": {
122                    "description": "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.",
123                    "type": "object",
124                    "additionalProperties": (__gen.subschema_for::<crate::api::resource::v1beta2::Counter>()),
125                },
126                "name": {
127                    "description": "Name defines the name of the counter set. It must be a DNS label.",
128                    "type": "string",
129                },
130            },
131            "required": [
132                "counters",
133                "name",
134            ],
135        })
136    }
137}