#
k8s_openapi/v1_35/apimachinery/pkg/apis/meta/v1/
group_resource.rs

    1// Generated from definition io.k8s.apimachinery.pkg.apis.meta.v1.GroupResource
    2
    3/// GroupResource specifies a Group and a Resource, but does not force a version.  This is useful for identifying concepts during lookup stages without having partially valid types
    4#[derive(Clone, Debug, Default, PartialEq)]
    5pub struct GroupResource {
    6    pub group: std::string::String,
    7
    8    pub resource: std::string::String,
    9}
    10
    11impl crate::DeepMerge for GroupResource {
    12    fn merge_from(&mut self, other: Self) {
    13        crate::DeepMerge::merge_from(&mut self.group, other.group);
    14        crate::DeepMerge::merge_from(&mut self.resource, other.resource);
    15    }
    16}
    17
    18impl<'de> crate::serde::Deserialize<'de> for GroupResource {
    19    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    20        #[allow(non_camel_case_types)]
    21        enum Field {
    22            Key_group,
    23            Key_resource,
    24            Other,
    25        }
    26
    27        impl<'de> crate::serde::Deserialize<'de> for Field {
    28            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    29                struct Visitor;
    30
    31                impl crate::serde::de::Visitor<'_> for Visitor {
    32                    type Value = Field;
    33
    34                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    35                        f.write_str("field identifier")
    36                    }
    37
    38                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
    39                        Ok(match v {
    40                            "group" => Field::Key_group,
    41                            "resource" => Field::Key_resource,
    42                            _ => Field::Other,
    43                        })
    44                    }
    45                }
    46
    47                deserializer.deserialize_identifier(Visitor)
    48            }
    49        }
    50
    51        struct Visitor;
    52
    53        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
    54            type Value = GroupResource;
    55
    56            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    57                f.write_str("GroupResource")
    58            }
    59
    60            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
    61                let mut value_group: Option<std::string::String> = None;
    62                let mut value_resource: Option<std::string::String> = None;
    63
    64                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
    65                    match key {
    66                        Field::Key_group => value_group = crate::serde::de::MapAccess::next_value(&mut map)?,
    67                        Field::Key_resource => value_resource = crate::serde::de::MapAccess::next_value(&mut map)?,
    68                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
    69                    }
    70                }
    71
    72                Ok(GroupResource {
    73                    group: value_group.unwrap_or_default(),
    74                    resource: value_resource.unwrap_or_default(),
    75                })
    76            }
    77        }
    78
    79        deserializer.deserialize_struct(
    80            "GroupResource",
    81            &[
    82                "group",
    83                "resource",
    84            ],
    85            Visitor,
    86        )
    87    }
    88}
    89
    90impl crate::serde::Serialize for GroupResource {
    91    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
    92        let mut state = serializer.serialize_struct(
    93            "GroupResource",
    94            2,
    95        )?;
    96        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "group", &self.group)?;
    97        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "resource", &self.resource)?;
    98        crate::serde::ser::SerializeStruct::end(state)
    99    }
    100}
    101
    102#[cfg(feature = "schemars")]
    103impl crate::schemars::JsonSchema for GroupResource {
    104    fn schema_name() -> std::borrow::Cow<'static, str> {
    105        "io.k8s.apimachinery.pkg.apis.meta.v1.GroupResource".into()
    106    }
    107
    108    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    109        crate::schemars::json_schema!({
    110            "description": "GroupResource specifies a Group and a Resource, but does not force a version.  This is useful for identifying concepts during lookup stages without having partially valid types",
    111            "type": "object",
    112            "properties": {
    113                "group": {
    114                    "type": "string",
    115                },
    116                "resource": {
    117                    "type": "string",
    118                },
    119            },
    120            "required": [
    121                "group",
    122                "resource",
    123            ],
    124        })
    125    }
    126}