optionable 0.14.0

Derive macro (and associated marker trait) to derive nested structs/enums with all subfields being optional (e.g. for patches or Kubernetes server side apply).
Documentation
#[derive(
    Clone,
    Default,
    PartialEq,
    serde::Deserialize,
    serde::Serialize,
    std::fmt::Debug
)]
/// Endpoint represents a single logical "backend" implementing a service.
#[serde(rename_all = "camelCase", deny_unknown_fields)]
pub struct EndpointAc {
    /// addresses of this endpoint. The contents of this field are interpreted according to the corresponding EndpointSlice addressType field. Consumers must handle different types of addresses in the context of their own capabilities. This must contain at least one address but no more than 100. These are all assumed to be fungible and clients may choose to only use the first element. Refer to: https://issue.k8s.io/106267
    #[serde(skip_serializing_if = "Option::is_none")]
    pub addresses: Option<std::vec::Vec<std::string::String>>,
    /// conditions contains information about the current status of the endpoint.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub conditions: Option<
        <::k8s_openapi027::api::discovery::v1::EndpointConditions as crate::Optionable>::Optioned,
    >,
    /// deprecatedTopology contains topology information part of the v1beta1 API. This field is deprecated, and will be removed when the v1beta1 API is removed (no sooner than kubernetes v1.24).  While this field can hold values, it is not writable through the v1 API, and any attempts to write to it will be silently ignored. Topology information can be found in the zone and nodeName fields instead.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub deprecated_topology: Option<
        std::collections::BTreeMap<std::string::String, std::string::String>,
    >,
    /// hints contains information associated with how an endpoint should be consumed.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub hints: Option<
        <::k8s_openapi027::api::discovery::v1::EndpointHints as crate::Optionable>::Optioned,
    >,
    /// hostname of this endpoint. This field may be used by consumers of endpoints to distinguish endpoints from each other (e.g. in DNS names). Multiple endpoints which use the same hostname should be considered fungible (e.g. multiple A values in DNS). Must be lowercase and pass DNS Label (RFC 1123) validation.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub hostname: Option<std::string::String>,
    /// nodeName represents the name of the Node hosting this endpoint. This can be used to determine endpoints local to a Node.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub node_name: Option<std::string::String>,
    /// targetRef is a reference to a Kubernetes object that represents this endpoint.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub target_ref: Option<
        <::k8s_openapi027::api::core::v1::ObjectReference as crate::Optionable>::Optioned,
    >,
    /// zone is the name of the Zone this endpoint exists in.
    #[serde(skip_serializing_if = "Option::is_none")]
    pub zone: Option<std::string::String>,
}
#[automatically_derived]
impl crate::Optionable for k8s_openapi027::api::discovery::v1::Endpoint {
    type Optioned = EndpointAc;
}
#[automatically_derived]
impl crate::Optionable for EndpointAc {
    type Optioned = EndpointAc;
}
#[automatically_derived]
#[cfg(feature = "k8s_openapi_convert")]
impl crate::OptionableConvert for k8s_openapi027::api::discovery::v1::Endpoint {
    fn into_optioned(self) -> EndpointAc {
        EndpointAc {
            addresses: Some(self.addresses),
            conditions: crate::OptionableConvert::into_optioned(self.conditions),
            deprecated_topology: self.deprecated_topology,
            hints: crate::OptionableConvert::into_optioned(self.hints),
            hostname: self.hostname,
            node_name: self.node_name,
            target_ref: crate::OptionableConvert::into_optioned(self.target_ref),
            zone: self.zone,
        }
    }
    fn try_from_optioned(value: EndpointAc) -> Result<Self, crate::Error> {
        Ok(Self {
            addresses: value
                .addresses
                .ok_or(crate::Error {
                    missing_field: "addresses",
                })?,
            conditions: crate::OptionableConvert::try_from_optioned(value.conditions)?,
            deprecated_topology: value.deprecated_topology,
            hints: crate::OptionableConvert::try_from_optioned(value.hints)?,
            hostname: value.hostname,
            node_name: value.node_name,
            target_ref: crate::OptionableConvert::try_from_optioned(value.target_ref)?,
            zone: value.zone,
        })
    }
    fn merge(&mut self, other: EndpointAc) -> Result<(), crate::Error> {
        if let Some(other_value) = other.addresses {
            crate::merge::try_merge_optioned_set(&mut self.addresses, other_value)?;
        }
        if self.conditions.is_none() {
            self.conditions = crate::OptionableConvert::try_from_optioned(
                other.conditions,
            )?;
        } else if let Some(self_value) = self.conditions.as_mut()
            && let Some(other_value) = other.conditions
        {
            crate::OptionableConvert::merge(self_value, other_value)?;
        }
        if self.deprecated_topology.is_none() {
            self.deprecated_topology = crate::OptionableConvert::try_from_optioned(
                other.deprecated_topology,
            )?;
        } else if let Some(self_value) = self.deprecated_topology.as_mut()
            && let Some(other_value) = other.deprecated_topology
        {
            crate::OptionableConvert::merge(self_value, other_value)?;
        }
        if self.hints.is_none() {
            self.hints = crate::OptionableConvert::try_from_optioned(other.hints)?;
        } else if let Some(self_value) = self.hints.as_mut()
            && let Some(other_value) = other.hints
        {
            crate::OptionableConvert::merge(self_value, other_value)?;
        }
        if self.hostname.is_none() {
            self.hostname = crate::OptionableConvert::try_from_optioned(other.hostname)?;
        } else if let Some(self_value) = self.hostname.as_mut()
            && let Some(other_value) = other.hostname
        {
            crate::OptionableConvert::merge(self_value, other_value)?;
        }
        if self.node_name.is_none() {
            self.node_name = crate::OptionableConvert::try_from_optioned(
                other.node_name,
            )?;
        } else if let Some(self_value) = self.node_name.as_mut()
            && let Some(other_value) = other.node_name
        {
            crate::OptionableConvert::merge(self_value, other_value)?;
        }
        if self.target_ref.is_none() {
            self.target_ref = crate::OptionableConvert::try_from_optioned(
                other.target_ref,
            )?;
        } else if let Some(self_value) = self.target_ref.as_mut()
            && let Some(other_value) = other.target_ref
        {
            crate::OptionableConvert::merge(self_value, other_value)?;
        }
        if self.zone.is_none() {
            self.zone = crate::OptionableConvert::try_from_optioned(other.zone)?;
        } else if let Some(self_value) = self.zone.as_mut()
            && let Some(other_value) = other.zone
        {
            crate::OptionableConvert::merge(self_value, other_value)?;
        }
        Ok(())
    }
}
#[automatically_derived]
#[cfg(feature = "k8s_openapi_convert")]
impl crate::OptionedConvert<k8s_openapi027::api::discovery::v1::Endpoint>
for EndpointAc {
    fn from_optionable(value: k8s_openapi027::api::discovery::v1::Endpoint) -> Self {
        crate::OptionableConvert::into_optioned(value)
    }
    fn try_into_optionable(
        self,
    ) -> Result<k8s_openapi027::api::discovery::v1::Endpoint, crate::Error> {
        crate::OptionableConvert::try_from_optioned(self)
    }
    fn merge_into(
        self,
        other: &mut k8s_openapi027::api::discovery::v1::Endpoint,
    ) -> Result<(), crate::Error> {
        crate::OptionableConvert::merge(other, self)
    }
}