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

    1// Generated from definition io.k8s.apimachinery.pkg.apis.meta.v1.Time
    2
    3/// Time is a wrapper around time.Time which supports correct marshaling to YAML and JSON.  Wrappers are provided for many of the factory methods that the time package offers.
    4#[derive(Clone, Debug, Eq, Ord, PartialEq, PartialOrd)]
    5pub struct Time(pub crate::jiff::Timestamp);
    6
    7impl crate::DeepMerge for Time {
    8    fn merge_from(&mut self, other: Self) {
    9        crate::DeepMerge::merge_from(&mut self.0, other.0);
    10    }
    11}
    12
    13impl<'de> crate::serde::Deserialize<'de> for Time {
    14    fn deserialize<D>(deserializer: D) -> Result<Self, D::Error> where D: crate::serde::Deserializer<'de> {
    15        struct Visitor;
    16
    17        impl<'de> crate::serde::de::Visitor<'de> for Visitor {
    18            type Value = Time;
    19
    20            fn expecting(&self, f: &mut core::fmt::Formatter<'_>) -> core::fmt::Result {
    21                f.write_str("Time")
    22            }
    23
    24            fn visit_newtype_struct<D>(self, deserializer: D) -> Result<Self::Value, D::Error> where D: crate::serde::Deserializer<'de> {
    25                Ok(Time(crate::serde::Deserialize::deserialize(deserializer)?))
    26            }
    27        }
    28
    29        deserializer.deserialize_newtype_struct("Time", Visitor)
    30    }
    31}
    32
    33impl From<crate::jiff::Timestamp> for Time {
    34    fn from(inner: crate::jiff::Timestamp) -> Self {
    35        Self(inner)
    36    }
    37}
    38
    39impl crate::serde::Serialize for Time {
    40    fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error> where S: crate::serde::Serializer {
    41        serializer.serialize_newtype_struct("Time", &crate::jiff::fmt::strtime::format("%Y-%m-%dT%H:%M:%SZ", self.0).map_err(crate::serde::ser::Error::custom)?)
    42    }
    43}
    44
    45#[cfg(feature = "schemars")]
    46impl crate::schemars::JsonSchema for Time {
    47    fn schema_name() -> std::borrow::Cow<'static, str> {
    48        "io.k8s.apimachinery.pkg.apis.meta.v1.Time".into()
    49    }
    50
    51    fn json_schema(__gen: &mut crate::schemars::SchemaGenerator) -> crate::schemars::Schema {
    52        crate::schemars::json_schema!({
    53            "description": "Time is a wrapper around time.Time which supports correct marshaling to YAML and JSON.  Wrappers are provided for many of the factory methods that the time package offers.",
    54            "type": "string",
    55            "format": "date-time",
    56        })
    57    }
    58}