Skip to content

Commit 05b8540

Browse files
committed
TypeInfo trait now returns Option<Cow> rather than Option<String>
Signed-off-by: clux <[email protected]>
1 parent 38458e0 commit 05b8540

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

kube-core/src/metadata.rs

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
use crate::{DynamicObject, Object};
33
pub use k8s_openapi::apimachinery::pkg::apis::meta::v1::{ListMeta, ObjectMeta};
44
use serde::{Deserialize, Serialize};
5+
use std::borrow::Cow;
56

67
/// Type information that is flattened into every kubernetes object
78
#[derive(Deserialize, Serialize, Clone, Default, Debug, Eq, PartialEq, Hash)]
@@ -32,9 +33,9 @@ pub trait TypeInfo {
3233
fn types_unchecked(&self) -> TypeMeta;
3334

3435
/// Get the `kind` of an object
35-
fn kind(&self) -> Option<String>;
36+
fn kind(&self) -> Option<Cow<'_, str>>;
3637
/// Get the `apiVersion` of any object
37-
fn api_version(&self) -> Option<String>;
38+
fn api_version(&self) -> Option<Cow<'_, str>>;
3839
/// Get a reference to the `ObjectMeta` of an object
3940
fn meta(&self) -> &ObjectMeta;
4041
/// Get a mutable reference to the `ObjectMeta` of an Object
@@ -59,11 +60,11 @@ where
5960
}
6061
}
6162

62-
fn kind(&self) -> Option<String> {
63+
fn kind(&self) -> Option<Cow<'_, str>> {
6364
Some(K::KIND.into())
6465
}
6566

66-
fn api_version(&self) -> Option<String> {
67+
fn api_version(&self) -> Option<Cow<'_, str>> {
6768
Some(K::API_VERSION.into())
6869
}
6970

@@ -90,12 +91,12 @@ where
9091
self.types.clone().unwrap()
9192
}
9293

93-
fn kind(&self) -> Option<String> {
94-
self.types.as_ref().map(|t| t.kind.clone())
94+
fn kind(&self) -> Option<Cow<'_, str>> {
95+
self.types.as_ref().map(|t| Cow::Borrowed(t.kind.as_ref()))
9596
}
9697

97-
fn api_version(&self) -> Option<String> {
98-
self.types.as_ref().map(|t| t.api_version.clone())
98+
fn api_version(&self) -> Option<Cow<'_, str>> {
99+
self.types.as_ref().map(|t| Cow::Borrowed(t.api_version.as_ref()))
99100
}
100101

101102
fn meta(&self) -> &ObjectMeta {
@@ -116,12 +117,12 @@ impl TypeInfo for DynamicObject {
116117
self.types.clone().unwrap()
117118
}
118119

119-
fn kind(&self) -> Option<String> {
120-
self.types.as_ref().map(|t| t.kind.clone())
120+
fn kind(&self) -> Option<Cow<'_, str>> {
121+
self.types.as_ref().map(|t| Cow::Borrowed(t.kind.as_ref()))
121122
}
122123

123-
fn api_version(&self) -> Option<String> {
124-
self.types.as_ref().map(|t| t.api_version.clone())
124+
fn api_version(&self) -> Option<Cow<'_, str>> {
125+
self.types.as_ref().map(|t| Cow::Borrowed(t.api_version.as_ref()))
125126
}
126127

127128
fn meta(&self) -> &ObjectMeta {

0 commit comments

Comments
 (0)