Skip to main content

k8s_openapi/v1_37/api/resource/v1alpha3/
shareable_capacity_status.rs

1// Generated from definition io.k8s.api.resource.v1alpha3.ShareableCapacityStatus
2
3/// ShareableCapacityStatus reports aggregate amounts for a single shareable capacity key.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct ShareableCapacityStatus {
6    /// Available is Total minus Consumed, never negative.
7    pub available: crate::apimachinery::pkg::api::resource::Quantity,
8
9    /// Consumed is the amount drawn by current allocations.
10    pub consumed: crate::apimachinery::pkg::api::resource::Quantity,
11
12    /// Name is the capacity name.
13    pub name: std::string::String,
14
15    /// Total is the sum of this capacity across shareable devices in the pool.
16    pub total: crate::apimachinery::pkg::api::resource::Quantity,
17}
18
19impl crate::DeepMerge for ShareableCapacityStatus {
20    fn merge_from(&mut self, other: Self) {
21        crate::DeepMerge::merge_from(&mut self.available, other.available);
22        crate::DeepMerge::merge_from(&mut self.consumed, other.consumed);
23        crate::DeepMerge::merge_from(&mut self.name, other.name);
24        crate::DeepMerge::merge_from(&mut self.total, other.total);
25    }
26}
27
28impl<'de> crate::serde::Deserialize<'de> for ShareableCapacityStatus {
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_available,
33            Key_consumed,
34            Key_name,
35            Key_total,
36            Other,
37        }
38
39        impl<'de> crate::serde::Deserialize<'de> for Field {
40            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
41                struct Visitor;
42
43                impl crate::serde::de::Visitor<'_> for Visitor {
44                    type Value = Field;
45
46                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
47                        f.write_str("field identifier")
48                    }
49
50                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
51                        Ok(match v {
52                            "available" => Field::Key_available,
53                            "consumed" => Field::Key_consumed,
54                            "name" => Field::Key_name,
55                            "total" => Field::Key_total,
56                            _ => Field::Other,
57                        })
58                    }
59                }
60
61                deserializer.deserialize_identifier(Visitor)
62            }
63        }
64
65        struct Visitor;
66
67        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
68            type Value = ShareableCapacityStatus;
69
70            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
71                f.write_str("ShareableCapacityStatus")
72            }
73
74            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
75                let mut value_available: Option<crate::apimachinery::pkg::api::resource::Quantity> = None;
76                let mut value_consumed: Option<crate::apimachinery::pkg::api::resource::Quantity> = None;
77                let mut value_name: Option<std::string::String> = None;
78                let mut value_total: Option<crate::apimachinery::pkg::api::resource::Quantity> = None;
79
80                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
81                    match key {
82                        Field::Key_available => value_available = crate::serde::de::MapAccess::next_value(&mut map)?,
83                        Field::Key_consumed => value_consumed = crate::serde::de::MapAccess::next_value(&mut map)?,
84                        Field::Key_name => value_name = crate::serde::de::MapAccess::next_value(&mut map)?,
85                        Field::Key_total => value_total = crate::serde::de::MapAccess::next_value(&mut map)?,
86                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
87                    }
88                }
89
90                Ok(ShareableCapacityStatus {
91                    available: value_available.unwrap_or_default(),
92                    consumed: value_consumed.unwrap_or_default(),
93                    name: value_name.unwrap_or_default(),
94                    total: value_total.unwrap_or_default(),
95                })
96            }
97        }
98
99        deserializer.deserialize_struct(
100            "ShareableCapacityStatus",
101            &[
102                "available",
103                "consumed",
104                "name",
105                "total",
106            ],
107            Visitor,
108        )
109    }
110}
111
112impl crate::serde::Serialize for ShareableCapacityStatus {
113    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
114        let mut state = serializer.serialize_struct(
115            "ShareableCapacityStatus",
116            4,
117        )?;
118        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "available", &self.available)?;
119        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "consumed", &self.consumed)?;
120        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "name", &self.name)?;
121        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "total", &self.total)?;
122        crate::serde::ser::SerializeStruct::end(state)
123    }
124}
125
126#[cfg(feature = "schemars")]
127impl crate::schemars::JsonSchema for ShareableCapacityStatus {
128    fn schema_name() -> std::borrow::Cow<'static, str> {
129        "io.k8s.api.resource.v1alpha3.ShareableCapacityStatus".into()
130    }
131
132    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
133        crate::schemars::json_schema!({
134            "description": "ShareableCapacityStatus reports aggregate amounts for a single shareable capacity key.",
135            "type": "object",
136            "properties": {
137                "available": ({
138                    let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::api::resource::Quantity>();
139                    schema_obj.ensure_object().insert("description".into(), "Available is Total minus Consumed, never negative.".into());
140                    schema_obj
141                }),
142                "consumed": ({
143                    let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::api::resource::Quantity>();
144                    schema_obj.ensure_object().insert("description".into(), "Consumed is the amount drawn by current allocations.".into());
145                    schema_obj
146                }),
147                "name": {
148                    "description": "Name is the capacity name.",
149                    "type": "string",
150                },
151                "total": ({
152                    let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::api::resource::Quantity>();
153                    schema_obj.ensure_object().insert("description".into(), "Total is the sum of this capacity across shareable devices in the pool.".into());
154                    schema_obj
155                }),
156            },
157            "required": [
158                "available",
159                "consumed",
160                "name",
161                "total",
162            ],
163        })
164    }
165}