#
k8s_openapi/v1_35/api/resource/v1/
device_counter_consumption.rs

    1// Generated from definition io.k8s.api.resource.v1.DeviceCounterConsumption
    2
    3/// DeviceCounterConsumption defines a set of counters that a device will consume from a CounterSet.
    4#[derive(Clone, Debug, Default, PartialEq)]
    5pub struct DeviceCounterConsumption {
    6    /// CounterSet is the name of the set from which the counters defined will be consumed.
    7    pub counter_set: std::string::String,
    8
    9    /// Counters defines the counters that will be consumed by the device.
    10    ///
    11    /// The maximum number of counters is 32.
    12    pub counters: std::collections::BTreeMap<std::string::String, crate::api::resource::v1::Counter>,
    13}
    14
    15impl crate::DeepMerge for DeviceCounterConsumption {
    16    fn merge_from(&mut self, other: Self) {
    17        crate::DeepMerge::merge_from(&mut self.counter_set, other.counter_set);
    18        crate::merge_strategies::map::granular(&mut self.counters, other.counters, |current_item, other_item| {
    19            crate::DeepMerge::merge_from(current_item, other_item);
    20        });
    21    }
    22}
    23
    24impl<'de> crate::serde::Deserialize<'de> for DeviceCounterConsumption {
    25    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    26        #[allow(non_camel_case_types)]
    27        enum Field {
    28            Key_counter_set,
    29            Key_counters,
    30            Other,
    31        }
    32
    33        impl<'de> crate::serde::Deserialize<'de> for Field {
    34            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    35                struct Visitor;
    36
    37                impl crate::serde::de::Visitor<'_> for Visitor {
    38                    type Value = Field;
    39
    40                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    41                        f.write_str("field identifier")
    42                    }
    43
    44                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
    45                        Ok(match v {
    46                            "counterSet" => Field::Key_counter_set,
    47                            "counters" => Field::Key_counters,
    48                            _ => Field::Other,
    49                        })
    50                    }
    51                }
    52
    53                deserializer.deserialize_identifier(Visitor)
    54            }
    55        }
    56
    57        struct Visitor;
    58
    59        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
    60            type Value = DeviceCounterConsumption;
    61
    62            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    63                f.write_str("DeviceCounterConsumption")
    64            }
    65
    66            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
    67                let mut value_counter_set: Option<std::string::String> = None;
    68                let mut value_counters: Option<std::collections::BTreeMap<std::string::String, crate::api::resource::v1::Counter>> = None;
    69
    70                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
    71                    match key {
    72                        Field::Key_counter_set => value_counter_set = crate::serde::de::MapAccess::next_value(&mut map)?,
    73                        Field::Key_counters => value_counters = crate::serde::de::MapAccess::next_value(&mut map)?,
    74                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
    75                    }
    76                }
    77
    78                Ok(DeviceCounterConsumption {
    79                    counter_set: value_counter_set.unwrap_or_default(),
    80                    counters: value_counters.unwrap_or_default(),
    81                })
    82            }
    83        }
    84
    85        deserializer.deserialize_struct(
    86            "DeviceCounterConsumption",
    87            &[
    88                "counterSet",
    89                "counters",
    90            ],
    91            Visitor,
    92        )
    93    }
    94}
    95
    96impl crate::serde::Serialize for DeviceCounterConsumption {
    97    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
    98        let mut state = serializer.serialize_struct(
    99            "DeviceCounterConsumption",
    100            2,
    101        )?;
    102        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "counterSet", &self.counter_set)?;
    103        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "counters", &self.counters)?;
    104        crate::serde::ser::SerializeStruct::end(state)
    105    }
    106}
    107
    108#[cfg(feature = "schemars")]
    109impl crate::schemars::JsonSchema for DeviceCounterConsumption {
    110    fn schema_name() -> std::borrow::Cow<'static, str> {
    111        "io.k8s.api.resource.v1.DeviceCounterConsumption".into()
    112    }
    113
    114    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    115        crate::schemars::json_schema!({
    116            "description": "DeviceCounterConsumption defines a set of counters that a device will consume from a CounterSet.",
    117            "type": "object",
    118            "properties": {
    119                "counterSet": {
    120                    "description": "CounterSet is the name of the set from which the counters defined will be consumed.",
    121                    "type": "string",
    122                },
    123                "counters": {
    124                    "description": "Counters defines the counters that will be consumed by the device.\n\nThe maximum number of counters is 32.",
    125                    "type": "object",
    126                    "additionalProperties": (__gen.subschema_for::<crate::api::resource::v1::Counter>()),
    127                },
    128            },
    129            "required": [
    130                "counterSet",
    131                "counters",
    132            ],
    133        })
    134    }
    135}