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

    1// Generated from definition io.k8s.api.core.v1.EndpointAddress
    2
    3/// EndpointAddress is a tuple that describes single IP address. Deprecated: This API is deprecated in v1.33+.
    4#[derive(Clone, Debug, Default, PartialEq)]
    5pub struct EndpointAddress {
    6    /// The Hostname of this endpoint
    7    pub hostname: Option<std::string::String>,
    8
    9    /// The IP of this endpoint. May not be loopback (127.0.0.0/8 or ::1), link-local (169.254.0.0/16 or fe80::/10), or link-local multicast (224.0.0.0/24 or ff02::/16).
    10    pub ip: std::string::String,
    11
    12    /// Optional: Node hosting this endpoint. This can be used to determine endpoints local to a node.
    13    pub node_name: Option<std::string::String>,
    14
    15    /// Reference to object providing the endpoint.
    16    pub target_ref: Option<crate::api::core::v1::ObjectReference>,
    17}
    18
    19impl crate::DeepMerge for EndpointAddress {
    20    fn merge_from(&mut self, other: Self) {
    21        crate::DeepMerge::merge_from(&mut self.hostname, other.hostname);
    22        crate::DeepMerge::merge_from(&mut self.ip, other.ip);
    23        crate::DeepMerge::merge_from(&mut self.node_name, other.node_name);
    24        crate::DeepMerge::merge_from(&mut self.target_ref, other.target_ref);
    25    }
    26}
    27
    28impl<'de> crate::serde::Deserialize<'de> for EndpointAddress {
    29    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    30        #[allow(non_camel_case_types)]
    31        enum Field {
    32            Key_hostname,
    33            Key_ip,
    34            Key_node_name,
    35            Key_target_ref,
    36            Other,
    37        }
    38
    39        impl<'de> crate::serde::Deserialize<'de> for Field {
    40            fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    41                struct Visitor;
    42
    43                impl crate::serde::de::Visitor<'_> for Visitor {
    44                    type Value = Field;
    45
    46                    fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    47                        f.write_str("field identifier")
    48                    }
    49
    50                    fn visit_str<E>(self, v: &str) -> Result<Self::Value, E> where E: crate::serde::de::Error {
    51                        Ok(match v {
    52                            "hostname" => Field::Key_hostname,
    53                            "ip" => Field::Key_ip,
    54                            "nodeName" => Field::Key_node_name,
    55                            "targetRef" => Field::Key_target_ref,
    56                            _ => Field::Other,
    57                        })
    58                    }
    59                }
    60
    61                deserializer.deserialize_identifier(Visitor)
    62            }
    63        }
    64
    65        struct Visitor;
    66
    67        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
    68            type Value = EndpointAddress;
    69
    70            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    71                f.write_str("EndpointAddress")
    72            }
    73
    74            fn visit_map<A>(self, mut map: A) -> Result<Self::Value, A::Error> where A: crate::serde::de::MapAccess<'de> {
    75                let mut value_hostname: Option<std::string::String> = None;
    76                let mut value_ip: Option<std::string::String> = None;
    77                let mut value_node_name: Option<std::string::String> = None;
    78                let mut value_target_ref: Option<crate::api::core::v1::ObjectReference> = None;
    79
    80                while let Some(key) = crate::serde::de::MapAccess::next_key::<Field>(&mut map)? {
    81                    match key {
    82                        Field::Key_hostname => value_hostname = crate::serde::de::MapAccess::next_value(&mut map)?,
    83                        Field::Key_ip => value_ip = crate::serde::de::MapAccess::next_value(&mut map)?,
    84                        Field::Key_node_name => value_node_name = crate::serde::de::MapAccess::next_value(&mut map)?,
    85                        Field::Key_target_ref => value_target_ref = crate::serde::de::MapAccess::next_value(&mut map)?,
    86                        Field::Other => { let _: crate::serde::de::IgnoredAny = crate::serde::de::MapAccess::next_value(&mut map)?; },
    87                    }
    88                }
    89
    90                Ok(EndpointAddress {
    91                    hostname: value_hostname,
    92                    ip: value_ip.unwrap_or_default(),
    93                    node_name: value_node_name,
    94                    target_ref: value_target_ref,
    95                })
    96            }
    97        }
    98
    99        deserializer.deserialize_struct(
    100            "EndpointAddress",
    101            &[
    102                "hostname",
    103                "ip",
    104                "nodeName",
    105                "targetRef",
    106            ],
    107            Visitor,
    108        )
    109    }
    110}
    111
    112impl crate::serde::Serialize for EndpointAddress {
    113    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
    114        let mut state = serializer.serialize_struct(
    115            "EndpointAddress",
    116            1 +
    117            self.hostname.as_ref().map_or(0, |_| 1) +
    118            self.node_name.as_ref().map_or(0, |_| 1) +
    119            self.target_ref.as_ref().map_or(0, |_| 1),
    120        )?;
    121        if let Some(value) = &self.hostname {
    122            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "hostname", value)?;
    123        }
    124        crate::serde::ser::SerializeStruct::serialize_field(&mut state, "ip", &self.ip)?;
    125        if let Some(value) = &self.node_name {
    126            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "nodeName", value)?;
    127        }
    128        if let Some(value) = &self.target_ref {
    129            crate::serde::ser::SerializeStruct::serialize_field(&mut state, "targetRef", value)?;
    130        }
    131        crate::serde::ser::SerializeStruct::end(state)
    132    }
    133}
    134
    135#[cfg(feature = "schemars")]
    136impl crate::schemars::JsonSchema for EndpointAddress {
    137    fn schema_name() -> std::borrow::Cow<'static, str> {
    138        "io.k8s.api.core.v1.EndpointAddress".into()
    139    }
    140
    141    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    142        crate::schemars::json_schema!({
    143            "description": "EndpointAddress is a tuple that describes single IP address. Deprecated: This API is deprecated in v1.33+.",
    144            "type": "object",
    145            "properties": {
    146                "hostname": {
    147                    "description": "The Hostname of this endpoint",
    148                    "type": "string",
    149                },
    150                "ip": {
    151                    "description": "The IP of this endpoint. May not be loopback (127.0.0.0/8 or ::1), link-local (169.254.0.0/16 or fe80::/10), or link-local multicast (224.0.0.0/24 or ff02::/16).",
    152                    "type": "string",
    153                },
    154                "nodeName": {
    155                    "description": "Optional: Node hosting this endpoint. This can be used to determine endpoints local to a node.",
    156                    "type": "string",
    157                },
    158                "targetRef": ({
    159                    let mut schema_obj = __gen.subschema_for::<crate::api::core::v1::ObjectReference>();
    160                    schema_obj.ensure_object().insert("description".into(), "Reference to object providing the endpoint.".into());
    161                    schema_obj
    162                }),
    163            },
    164            "required": [
    165                "ip",
    166            ],
    167        })
    168    }
    169}