1// Generated from definition io.k8s.api.resource.v1beta1.CounterSet
23/// 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 is 32.
11pub counters: std::collections::BTreeMap<std::string::String, crate::api::resource::v1beta1::Counter>,
1213/// Name defines the name of the counter set. It must be a DNS label.
14pub name: std::string::String,
15}
1617impl crate::DeepMerge for CounterSet {
18fn merge_from(&mut self, other: Self) {
19crate::merge_strategies::map::granular(&mut self.counters, other.counters, |current_item, other_item| {
20crate::DeepMerge::merge_from(current_item, other_item);
21 });
22crate::DeepMerge::merge_from(&mut self.name, other.name);
23 }
24}
2526impl<'de> crate::serde::Deserialize<'de> for CounterSet {
27fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
28#[allow(non_camel_case_types)]
29enum Field {
30 Key_counters,
31 Key_name,
32 Other,
33 }
3435impl<'de> crate::serde::Deserialize<'de> for Field {
36fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
37struct Visitor;
3839impl crate::serde::de::Visitor<'_> for Visitor {
40type Value = Field;
4142fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
43 f.write_str("field identifier")
44 }
4546fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
47Ok(match v {
48"counters" => Field::Key_counters,
49"name" => Field::Key_name,
50_ => Field::Other,
51 })
52 }
53 }
5455 deserializer.deserialize_identifier(Visitor)
56 }
57 }
5859struct Visitor;
6061impl<'de> crate::serde::de::Visitor<'de> for Visitor {
62type Value = CounterSet;
6364fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
65 f.write_str("CounterSet")
66 }
6768fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
69let mut value_counters: Option<std::collections::BTreeMap<std::string::String, crate::api::resource::v1beta1::Counter>> = None;
70let mut value_name: Option<std::string::String> = None;
7172while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
73match 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 }
7980Ok(CounterSet {
81 counters: value_counters.unwrap_or_default(),
82 name: value_name.unwrap_or_default(),
83 })
84 }
85 }
8687 deserializer.deserialize_struct(
88"CounterSet",
89&[
90"counters",
91"name",
92 ],
93 Visitor,
94 )
95 }
96}
9798impl crate::serde::Serialize for CounterSet {
99fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
100let mut state = serializer.serialize_struct(
101"CounterSet",
1022,
103 )?;
104crate::serde::ser::SerializeStruct::serialize_field(&mut state, "counters", &self.counters)?;
105crate::serde::ser::SerializeStruct::serialize_field(&mut state, "name", &self.name)?;
106crate::serde::ser::SerializeStruct::end(state)
107 }
108}
109110#[cfg(feature = "schemars")]
111impl crate::schemars::JsonSchema for CounterSet {
112fn schema_name() -> std::string::String {
113"io.k8s.api.resource.v1beta1.CounterSet".into()
114 }
115116fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
117crate::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(),
127crate::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 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::v1beta1::Counter>())),
135 ..Default::default()
136 })),
137 ..Default::default()
138 }),
139 ),
140 (
141"name".into(),
142crate::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}