#
k8s_openapi/v1_35/api/resource/v1beta1/
device_claim.rs

    1// Generated from definition io.k8s.api.resource.v1beta1.DeviceClaim
    2
    3/// DeviceClaim defines how to request devices with a ResourceClaim.
    4#[derive(Clone, Debug, Default, PartialEq)]
    5pub struct DeviceClaim {
    6    /// This field holds configuration for multiple potential drivers which could satisfy requests in this claim. It is ignored while allocating the claim.
    7    pub config: Option<std::vec::Vec<crate::api::resource::v1beta1::DeviceClaimConfiguration>>,
    8
    9    /// These constraints must be satisfied by the set of devices that get allocated for the claim.
    10    pub constraints: Option<std::vec::Vec<crate::api::resource::v1beta1::DeviceConstraint>>,
    11
    12    /// Requests represent individual requests for distinct devices which must all be satisfied. If empty, nothing needs to be allocated.
    13    pub requests: Option<std::vec::Vec<crate::api::resource::v1beta1::DeviceRequest>>,
    14}
    15
    16impl crate::DeepMerge for DeviceClaim {
    17    fn merge_from(&mut self, other: Self) {
    18        crate::merge_strategies::list::atomic(&mut self.config, other.config);
    19        crate::merge_strategies::list::atomic(&mut self.constraints, other.constraints);
    20        crate::merge_strategies::list::atomic(&mut self.requests, other.requests);
    21    }
    22}
    23
    24impl<'de> crate::serde::Deserialize<'de> for DeviceClaim {
    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_config,
    29            Key_constraints,
    30            Key_requests,
    31            Other,
    32        }
    33
    34        impl<'de> crate::serde::Deserialize<'de> for Field {
    35            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    36                struct Visitor;
    37
    38                impl crate::serde::de::Visitor<'_> for Visitor {
    39                    type Value = Field;
    40
    41                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    42                        f.write_str("field identifier")
    43                    }
    44
    45                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
    46                        Ok(match v {
    47                            "config" => Field::Key_config,
    48                            "constraints" => Field::Key_constraints,
    49                            "requests" => Field::Key_requests,
    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 = DeviceClaim;
    63
    64            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    65                f.write_str("DeviceClaim")
    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_config: Option<std::vec::Vec<crate::api::resource::v1beta1::DeviceClaimConfiguration>> = None;
    70                let mut value_constraints: Option<std::vec::Vec<crate::api::resource::v1beta1::DeviceConstraint>> = None;
    71                let mut value_requests: Option<std::vec::Vec<crate::api::resource::v1beta1::DeviceRequest>> = None;
    72
    73                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
    74                    match key {
    75                        Field::Key_config => value_config = crate::serde::de::MapAccess::next_value(&mut map)?,
    76                        Field::Key_constraints => value_constraints = crate::serde::de::MapAccess::next_value(&mut map)?,
    77                        Field::Key_requests => value_requests = crate::serde::de::MapAccess::next_value(&mut map)?,
    78                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
    79                    }
    80                }
    81
    82                Ok(DeviceClaim {
    83                    config: value_config,
    84                    constraints: value_constraints,
    85                    requests: value_requests,
    86                })
    87            }
    88        }
    89
    90        deserializer.deserialize_struct(
    91            "DeviceClaim",
    92            &[
    93                "config",
    94                "constraints",
    95                "requests",
    96            ],
    97            Visitor,
    98        )
    99    }
    100}
    101
    102impl crate::serde::Serialize for DeviceClaim {
    103    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
    104        let mut state = serializer.serialize_struct(
    105            "DeviceClaim",
    106            self.config.as_ref().map_or(0, |_| 1) +
    107            self.constraints.as_ref().map_or(0, |_| 1) +
    108            self.requests.as_ref().map_or(0, |_| 1),
    109        )?;
    110        if let Some(value) = &self.config {
    111            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "config", value)?;
    112        }
    113        if let Some(value) = &self.constraints {
    114            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "constraints", value)?;
    115        }
    116        if let Some(value) = &self.requests {
    117            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "requests", value)?;
    118        }
    119        crate::serde::ser::SerializeStruct::end(state)
    120    }
    121}
    122
    123#[cfg(feature = "schemars")]
    124impl crate::schemars::JsonSchema for DeviceClaim {
    125    fn schema_name() -> std::borrow::Cow<'static, str> {
    126        "io.k8s.api.resource.v1beta1.DeviceClaim".into()
    127    }
    128
    129    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    130        crate::schemars::json_schema!({
    131            "description": "DeviceClaim defines how to request devices with a ResourceClaim.",
    132            "type": "object",
    133            "properties": {
    134                "config": {
    135                    "description": "This field holds configuration for multiple potential drivers which could satisfy requests in this claim. It is ignored while allocating the claim.",
    136                    "type": "array",
    137                    "items": (__gen.subschema_for::<crate::api::resource::v1beta1::DeviceClaimConfiguration>()),
    138                },
    139                "constraints": {
    140                    "description": "These constraints must be satisfied by the set of devices that get allocated for the claim.",
    141                    "type": "array",
    142                    "items": (__gen.subschema_for::<crate::api::resource::v1beta1::DeviceConstraint>()),
    143                },
    144                "requests": {
    145                    "description": "Requests represent individual requests for distinct devices which must all be satisfied. If empty, nothing needs to be allocated.",
    146                    "type": "array",
    147                    "items": (__gen.subschema_for::<crate::api::resource::v1beta1::DeviceRequest>()),
    148                },
    149            },
    150        })
    151    }
    152}