#
k8s_openapi/v1_35/api/core/v1/
binding.rs

    1// Generated from definition io.k8s.api.core.v1.Binding
    2
    3/// Binding ties one object to another; for example, a pod is bound to a node by a scheduler.
    4#[derive(Clone, Debug, Default, PartialEq)]
    5pub struct Binding {
    6    /// Standard object's metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata
    7    pub metadata: crate::apimachinery::pkg::apis::meta::v1::ObjectMeta,
    8
    9    /// The target object that you want to bind to the standard object.
    10    pub target: crate::api::core::v1::ObjectReference,
    11}
    12
    13impl crate::Resource for Binding {
    14    const API_VERSION: &'static str = "v1";
    15    const GROUP: &'static str = "";
    16    const KIND: &'static str = "Binding";
    17    const VERSION: &'static str = "v1";
    18    const URL_PATH_SEGMENT: &'static str = "bindings";
    19    type Scope = crate::NamespaceResourceScope;
    20}
    21
    22impl crate::Metadata for Binding {
    23    type Ty = crate::apimachinery::pkg::apis::meta::v1::ObjectMeta;
    24
    25    fn metadata(&self) -> &<Self as crate::Metadata>::Ty {
    26        &self.metadata
    27    }
    28
    29    fn metadata_mut(&mut self) -> &mut<Self as crate::Metadata>::Ty {
    30        &mut self.metadata
    31    }
    32}
    33
    34impl crate::DeepMerge for Binding {
    35    fn merge_from(&mut self, other: Self) {
    36        crate::DeepMerge::merge_from(&mut self.metadata, other.metadata);
    37        crate::DeepMerge::merge_from(&mut self.target, other.target);
    38    }
    39}
    40
    41impl<'de> crate::serde::Deserialize<'de> for Binding {
    42    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    43        #[allow(non_camel_case_types)]
    44        enum Field {
    45            Key_api_version,
    46            Key_kind,
    47            Key_metadata,
    48            Key_target,
    49            Other,
    50        }
    51
    52        impl<'de> crate::serde::Deserialize<'de> for Field {
    53            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    54                struct Visitor;
    55
    56                impl crate::serde::de::Visitor<'_> for Visitor {
    57                    type Value = Field;
    58
    59                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    60                        f.write_str("field identifier")
    61                    }
    62
    63                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
    64                        Ok(match v {
    65                            "apiVersion" => Field::Key_api_version,
    66                            "kind" => Field::Key_kind,
    67                            "metadata" => Field::Key_metadata,
    68                            "target" => Field::Key_target,
    69                            _ => Field::Other,
    70                        })
    71                    }
    72                }
    73
    74                deserializer.deserialize_identifier(Visitor)
    75            }
    76        }
    77
    78        struct Visitor;
    79
    80        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
    81            type Value = Binding;
    82
    83            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    84                f.write_str(<Self::Value as crate::Resource>::KIND)
    85            }
    86
    87            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
    88                let mut value_metadata: Option<crate::apimachinery::pkg::apis::meta::v1::ObjectMeta> = None;
    89                let mut value_target: Option<crate::api::core::v1::ObjectReference> = None;
    90
    91                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
    92                    match key {
    93                        Field::Key_api_version => {
    94                            let value_api_version: std::string::String = crate::serde::de::MapAccess::next_value(&mut map)?;
    95                            if value_api_version != <Self::Value as crate::Resource>::API_VERSION {
    96                                return Err(crate::serde::de::Error::invalid_value(crate::serde::de::Unexpected::Str(&value_api_version), &<Self::Value as crate::Resource>::API_VERSION));
    97                            }
    98                        },
    99                        Field::Key_kind => {
    100                            let value_kind: std::string::String = crate::serde::de::MapAccess::next_value(&mut map)?;
    101                            if value_kind != <Self::Value as crate::Resource>::KIND {
    102                                return Err(crate::serde::de::Error::invalid_value(crate::serde::de::Unexpected::Str(&value_kind), &<Self::Value as crate::Resource>::KIND));
    103                            }
    104                        },
    105                        Field::Key_metadata => value_metadata = crate::serde::de::MapAccess::next_value(&mut map)?,
    106                        Field::Key_target => value_target = crate::serde::de::MapAccess::next_value(&mut map)?,
    107                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
    108                    }
    109                }
    110
    111                Ok(Binding {
    112                    metadata: value_metadata.unwrap_or_default(),
    113                    target: value_target.unwrap_or_default(),
    114                })
    115            }
    116        }
    117
    118        deserializer.deserialize_struct(
    119            <Self as crate::Resource>::KIND,
    120            &[
    121                "apiVersion",
    122                "kind",
    123                "metadata",
    124                "target",
    125            ],
    126            Visitor,
    127        )
    128    }
    129}
    130
    131impl crate::serde::Serialize for Binding {
    132    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
    133        let mut state = serializer.serialize_struct(
    134            <Self as crate::Resource>::KIND,
    135            4,
    136        )?;
    137        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "apiVersion", <Self as crate::Resource>::API_VERSION)?;
    138        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "kind", <Self as crate::Resource>::KIND)?;
    139        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "metadata", &self.metadata)?;
    140        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "target", &self.target)?;
    141        crate::serde::ser::SerializeStruct::end(state)
    142    }
    143}
    144
    145#[cfg(feature = "schemars")]
    146impl crate::schemars::JsonSchema for Binding {
    147    fn schema_name() -> std::borrow::Cow<'static, str> {
    148        "io.k8s.api.core.v1.Binding".into()
    149    }
    150
    151    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    152        crate::schemars::json_schema!({
    153            "description": "Binding ties one object to another; for example, a pod is bound to a node by a scheduler.",
    154            "type": "object",
    155            "properties": {
    156                "apiVersion": {
    157                    "description": "APIVersion defines the versioned schema of this representation of an object. Servers should convert recognized schemas to the latest internal value, and may reject unrecognized values. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#resources",
    158                    "type": "string",
    159                },
    160                "kind": {
    161                    "description": "Kind is a string value representing the REST resource this object represents. Servers may infer this from the endpoint the client submits requests to. Cannot be updated. In CamelCase. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#types-kinds",
    162                    "type": "string",
    163                },
    164                "metadata": ({
    165                    let mut schema_obj = __gen.subschema_for::<crate::apimachinery::pkg::apis::meta::v1::ObjectMeta>();
    166                    schema_obj.ensure_object().insert("description".into(), "Standard object's metadata. More info: https://git.k8s.io/community/contributors/devel/sig-architecture/api-conventions.md#metadata".into());
    167                    schema_obj
    168                }),
    169                "target": ({
    170                    let mut schema_obj = __gen.subschema_for::<crate::api::core::v1::ObjectReference>();
    171                    schema_obj.ensure_object().insert("description".into(), "The target object that you want to bind to the standard object.".into());
    172                    schema_obj
    173                }),
    174            },
    175            "required": [
    176                "metadata",
    177                "target",
    178            ],
    179        })
    180    }
    181}