#
k8s_openapi/v1_35/api/resource/v1beta2/
device_allocation_configuration.rs

    1// Generated from definition io.k8s.api.resource.v1beta2.DeviceAllocationConfiguration
    2
    3/// DeviceAllocationConfiguration gets embedded in an AllocationResult.
    4#[derive(Clone, Debug, Default, PartialEq)]
    5pub struct DeviceAllocationConfiguration {
    6    /// Opaque provides driver-specific configuration parameters.
    7    pub opaque: Option<crate::api::resource::v1beta2::OpaqueDeviceConfiguration>,
    8
    9    /// Requests lists the names of requests where the configuration applies. If empty, its applies to all requests.
    10    ///
    11    /// References to subrequests must include the name of the main request and may include the subrequest using the format \<main request\>\[/\<subrequest\>\]. If just the main request is given, the configuration applies to all subrequests.
    12    pub requests: Option<std::vec::Vec<std::string::String>>,
    13
    14    /// Source records whether the configuration comes from a class and thus is not something that a normal user would have been able to set or from a claim.
    15    pub source: std::string::String,
    16}
    17
    18impl crate::DeepMerge for DeviceAllocationConfiguration {
    19    fn merge_from(&mut self, other: Self) {
    20        crate::DeepMerge::merge_from(&mut self.opaque, other.opaque);
    21        crate::merge_strategies::list::atomic(&mut self.requests, other.requests);
    22        crate::DeepMerge::merge_from(&mut self.source, other.source);
    23    }
    24}
    25
    26impl<'de> crate::serde::Deserialize<'de> for DeviceAllocationConfiguration {
    27    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    28        #[allow(non_camel_case_types)]
    29        enum Field {
    30            Key_opaque,
    31            Key_requests,
    32            Key_source,
    33            Other,
    34        }
    35
    36        impl<'de> crate::serde::Deserialize<'de> for Field {
    37            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    38                struct Visitor;
    39
    40                impl crate::serde::de::Visitor<'_> for Visitor {
    41                    type Value = Field;
    42
    43                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    44                        f.write_str("field identifier")
    45                    }
    46
    47                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
    48                        Ok(match v {
    49                            "opaque" => Field::Key_opaque,
    50                            "requests" => Field::Key_requests,
    51                            "source" => Field::Key_source,
    52                            _ => Field::Other,
    53                        })
    54                    }
    55                }
    56
    57                deserializer.deserialize_identifier(Visitor)
    58            }
    59        }
    60
    61        struct Visitor;
    62
    63        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
    64            type Value = DeviceAllocationConfiguration;
    65
    66            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    67                f.write_str("DeviceAllocationConfiguration")
    68            }
    69
    70            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
    71                let mut value_opaque: Option<crate::api::resource::v1beta2::OpaqueDeviceConfiguration> = None;
    72                let mut value_requests: Option<std::vec::Vec<std::string::String>> = None;
    73                let mut value_source: Option<std::string::String> = None;
    74
    75                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
    76                    match key {
    77                        Field::Key_opaque => value_opaque = crate::serde::de::MapAccess::next_value(&mut map)?,
    78                        Field::Key_requests => value_requests = crate::serde::de::MapAccess::next_value(&mut map)?,
    79                        Field::Key_source => value_source = crate::serde::de::MapAccess::next_value(&mut map)?,
    80                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
    81                    }
    82                }
    83
    84                Ok(DeviceAllocationConfiguration {
    85                    opaque: value_opaque,
    86                    requests: value_requests,
    87                    source: value_source.unwrap_or_default(),
    88                })
    89            }
    90        }
    91
    92        deserializer.deserialize_struct(
    93            "DeviceAllocationConfiguration",
    94            &[
    95                "opaque",
    96                "requests",
    97                "source",
    98            ],
    99            Visitor,
    100        )
    101    }
    102}
    103
    104impl crate::serde::Serialize for DeviceAllocationConfiguration {
    105    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
    106        let mut state = serializer.serialize_struct(
    107            "DeviceAllocationConfiguration",
    108            1 +
    109            self.opaque.as_ref().map_or(0, |_| 1) +
    110            self.requests.as_ref().map_or(0, |_| 1),
    111        )?;
    112        if let Some(value) = &self.opaque {
    113            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "opaque", value)?;
    114        }
    115        if let Some(value) = &self.requests {
    116            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "requests", value)?;
    117        }
    118        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "source", &self.source)?;
    119        crate::serde::ser::SerializeStruct::end(state)
    120    }
    121}
    122
    123#[cfg(feature = "schemars")]
    124impl crate::schemars::JsonSchema for DeviceAllocationConfiguration {
    125    fn schema_name() -> std::borrow::Cow<'static, str> {
    126        "io.k8s.api.resource.v1beta2.DeviceAllocationConfiguration".into()
    127    }
    128
    129    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    130        crate::schemars::json_schema!({
    131            "description": "DeviceAllocationConfiguration gets embedded in an AllocationResult.",
    132            "type": "object",
    133            "properties": {
    134                "opaque": ({
    135                    let mut schema_obj = __gen.subschema_for::<crate::api::resource::v1beta2::OpaqueDeviceConfiguration>();
    136                    schema_obj.ensure_object().insert("description".into(), "Opaque provides driver-specific configuration parameters.".into());
    137                    schema_obj
    138                }),
    139                "requests": {
    140                    "description": "Requests lists the names of requests where the configuration applies. If empty, its applies to all requests.\n\nReferences to subrequests must include the name of the main request and may include the subrequest using the format <main request>[/<subrequest>]. If just the main request is given, the configuration applies to all subrequests.",
    141                    "type": "array",
    142                    "items": {
    143                        "type": "string",
    144                    },
    145                },
    146                "source": {
    147                    "description": "Source records whether the configuration comes from a class and thus is not something that a normal user would have been able to set or from a claim.",
    148                    "type": "string",
    149                },
    150            },
    151            "required": [
    152                "source",
    153            ],
    154        })
    155    }
    156}