From 05b85404299d590a4d282b9f6b8495b71ee85732 Mon Sep 17 00:00:00 2001 From: clux Date: Mon, 12 Dec 2022 07:45:56 +0000 Subject: [PATCH] TypeInfo trait now returns Option rather than Option Signed-off-by: clux --- kube-core/src/metadata.rs | 25 +++++++++++++------------ 1 file changed, 13 insertions(+), 12 deletions(-) diff --git a/kube-core/src/metadata.rs b/kube-core/src/metadata.rs index 311e3bd3a..197cd45f5 100644 --- a/kube-core/src/metadata.rs +++ b/kube-core/src/metadata.rs @@ -2,6 +2,7 @@ use crate::{DynamicObject, Object}; pub use k8s_openapi::apimachinery::pkg::apis::meta::v1::{ListMeta, ObjectMeta}; use serde::{Deserialize, Serialize}; +use std::borrow::Cow; /// Type information that is flattened into every kubernetes object #[derive(Deserialize, Serialize, Clone, Default, Debug, Eq, PartialEq, Hash)] @@ -32,9 +33,9 @@ pub trait TypeInfo { fn types_unchecked(&self) -> TypeMeta; /// Get the `kind` of an object - fn kind(&self) -> Option; + fn kind(&self) -> Option>; /// Get the `apiVersion` of any object - fn api_version(&self) -> Option; + fn api_version(&self) -> Option>; /// Get a reference to the `ObjectMeta` of an object fn meta(&self) -> &ObjectMeta; /// Get a mutable reference to the `ObjectMeta` of an Object @@ -59,11 +60,11 @@ where } } - fn kind(&self) -> Option { + fn kind(&self) -> Option> { Some(K::KIND.into()) } - fn api_version(&self) -> Option { + fn api_version(&self) -> Option> { Some(K::API_VERSION.into()) } @@ -90,12 +91,12 @@ where self.types.clone().unwrap() } - fn kind(&self) -> Option { - self.types.as_ref().map(|t| t.kind.clone()) + fn kind(&self) -> Option> { + self.types.as_ref().map(|t| Cow::Borrowed(t.kind.as_ref())) } - fn api_version(&self) -> Option { - self.types.as_ref().map(|t| t.api_version.clone()) + fn api_version(&self) -> Option> { + self.types.as_ref().map(|t| Cow::Borrowed(t.api_version.as_ref())) } fn meta(&self) -> &ObjectMeta { @@ -116,12 +117,12 @@ impl TypeInfo for DynamicObject { self.types.clone().unwrap() } - fn kind(&self) -> Option { - self.types.as_ref().map(|t| t.kind.clone()) + fn kind(&self) -> Option> { + self.types.as_ref().map(|t| Cow::Borrowed(t.kind.as_ref())) } - fn api_version(&self) -> Option { - self.types.as_ref().map(|t| t.api_version.clone()) + fn api_version(&self) -> Option> { + self.types.as_ref().map(|t| Cow::Borrowed(t.api_version.as_ref())) } fn meta(&self) -> &ObjectMeta {