k8s_openapi/v1_32/api/resource/v1alpha3/
device_allocation_result.rs

1// Generated from definition io.k8s.api.resource.v1alpha3.DeviceAllocationResult
2
3/// DeviceAllocationResult is the result of allocating devices.
4#[derive(Clone, Debug, Default, PartialEq)]
5pub struct DeviceAllocationResult {
6    /// This field is a combination of all the claim and class configuration parameters. Drivers can distinguish between those based on a flag.
7    ///
8    /// This includes configuration parameters for drivers which have no allocated devices in the result because it is up to the drivers which configuration parameters they support. They can silently ignore unknown configuration parameters.
9    pub config: Option<Vec<crate::api::resource::v1alpha3::DeviceAllocationConfiguration>>,
10
11    /// Results lists all allocated devices.
12    pub results: Option<Vec<crate::api::resource::v1alpha3::DeviceRequestAllocationResult>>,
13}
14
15impl crate::DeepMerge for DeviceAllocationResult {
16    fn merge_from(&mut self, other: Self) {
17        crate::merge_strategies::list::atomic(&mut self.config, other.config);
18        crate::merge_strategies::list::atomic(&mut self.results, other.results);
19    }
20}
21
22impl<'de> crate::serde::Deserialize<'de> for DeviceAllocationResult {
23    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
24        #[allow(non_camel_case_types)]
25        enum Field {
26            Key_config,
27            Key_results,
28            Other,
29        }
30
31        impl<'de> crate::serde::Deserialize<'de> for Field {
32            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
33                struct Visitor;
34
35                impl crate::serde::de::Visitor<'_> for Visitor {
36                    type Value = Field;
37
38                    fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
39                        f.write_str("field identifier")
40                    }
41
42                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
43                        Ok(match v {
44                            "config" => Field::Key_config,
45                            "results" => Field::Key_results,
46                            _ => Field::Other,
47                        })
48                    }
49                }
50
51                deserializer.deserialize_identifier(Visitor)
52            }
53        }
54
55        struct Visitor;
56
57        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
58            type Value = DeviceAllocationResult;
59
60            fn expecting(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
61                f.write_str("DeviceAllocationResult")
62            }
63
64            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
65                let mut value_config: Option<Vec<crate::api::resource::v1alpha3::DeviceAllocationConfiguration>> = None;
66                let mut value_results: Option<Vec<crate::api::resource::v1alpha3::DeviceRequestAllocationResult>> = None;
67
68                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
69                    match key {
70                        Field::Key_config => value_config = crate::serde::de::MapAccess::next_value(&mut map)?,
71                        Field::Key_results => value_results = crate::serde::de::MapAccess::next_value(&mut map)?,
72                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
73                    }
74                }
75
76                Ok(DeviceAllocationResult {
77                    config: value_config,
78                    results: value_results,
79                })
80            }
81        }
82
83        deserializer.deserialize_struct(
84            "DeviceAllocationResult",
85            &[
86                "config",
87                "results",
88            ],
89            Visitor,
90        )
91    }
92}
93
94impl crate::serde::Serialize for DeviceAllocationResult {
95    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
96        let mut state = serializer.serialize_struct(
97            "DeviceAllocationResult",
98            self.config.as_ref().map_or(0, |_| 1) +
99            self.results.as_ref().map_or(0, |_| 1),
100        )?;
101        if let Some(value) = &self.config {
102            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "config", value)?;
103        }
104        if let Some(value) = &self.results {
105            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "results", value)?;
106        }
107        crate::serde::ser::SerializeStruct::end(state)
108    }
109}
110
111#[cfg(feature = "schemars")]
112impl crate::schemars::JsonSchema for DeviceAllocationResult {
113    fn schema_name() -> String {
114        "io.k8s.api.resource.v1alpha3.DeviceAllocationResult".to_owned()
115    }
116
117    fn json_schema(__gen: &mut crate::schemars::gen::SchemaGenerator) -> crate::schemars::schema::Schema {
118        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
119            metadata: Some(Box::new(crate::schemars::schema::Metadata {
120                description: Some("DeviceAllocationResult is the result of allocating devices.".to_owned()),
121                ..Default::default()
122            })),
123            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Object))),
124            object: Some(Box::new(crate::schemars::schema::ObjectValidation {
125                properties: [
126                    (
127                        "config".to_owned(),
128                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
129                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
130                                description: Some("This field is a combination of all the claim and class configuration parameters. Drivers can distinguish between those based on a flag.\n\nThis includes configuration parameters for drivers which have no allocated devices in the result because it is up to the drivers which configuration parameters they support. They can silently ignore unknown configuration parameters.".to_owned()),
131                                ..Default::default()
132                            })),
133                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Array))),
134                            array: Some(Box::new(crate::schemars::schema::ArrayValidation {
135                                items: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(__gen.subschema_for::<crate::api::resource::v1alpha3::DeviceAllocationConfiguration>()))),
136                                ..Default::default()
137                            })),
138                            ..Default::default()
139                        }),
140                    ),
141                    (
142                        "results".to_owned(),
143                        crate::schemars::schema::Schema::Object(crate::schemars::schema::SchemaObject {
144                            metadata: Some(Box::new(crate::schemars::schema::Metadata {
145                                description: Some("Results lists all allocated devices.".to_owned()),
146                                ..Default::default()
147                            })),
148                            instance_type: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(crate::schemars::schema::InstanceType::Array))),
149                            array: Some(Box::new(crate::schemars::schema::ArrayValidation {
150                                items: Some(crate::schemars::schema::SingleOrVec::Single(Box::new(__gen.subschema_for::<crate::api::resource::v1alpha3::DeviceRequestAllocationResult>()))),
151                                ..Default::default()
152                            })),
153                            ..Default::default()
154                        }),
155                    ),
156                ].into(),
157                ..Default::default()
158            })),
159            ..Default::default()
160        })
161    }
162}