Skip to content

Commit

Permalink
rename ToObjectRef to reflector::Lookup
Browse files Browse the repository at this point in the history
  • Loading branch information
SOF3 committed Mar 3, 2024
1 parent 6baf5c0 commit 57e141e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions kube-runtime/src/reflector/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
mod object_ref;
pub mod store;

pub use self::object_ref::{Extra as ObjectRefExtra, ObjectRef, ToObjectRef};
pub use self::object_ref::{Extra as ObjectRefExtra, ObjectRef, Lookup};
use crate::watcher;
use futures::{Stream, TryStreamExt};
use std::hash::Hash;
Expand Down Expand Up @@ -90,7 +90,7 @@ pub use store::{store, Store};
/// Additionally, only `labels`, `annotations` and `managed_fields` are safe to drop from `ObjectMeta`.
pub fn reflector<K, W>(mut writer: store::Writer<K>, stream: W) -> impl Stream<Item = W::Item>
where
K: ToObjectRef + Clone,
K: Lookup + Clone,
K::DynamicType: Eq + Hash + Clone,
W: Stream<Item = watcher::Result<watcher::Event<K>>>,
{
Expand Down
20 changes: 10 additions & 10 deletions kube-runtime/src/reflector/object_ref.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use std::{
///
/// This trait is blanket-implemented for all [`Resource`] objects.
#[allow(clippy::module_name_repetitions)]
pub trait ToObjectRef {
pub trait Lookup {
/// Type information for types that do not know their resource information at compile time.
/// This is equivalent to [`Resource::DynamicType`].
type DynamicType;
Expand Down Expand Up @@ -62,7 +62,7 @@ pub trait ToObjectRef {
}
}

impl<K: Resource> ToObjectRef for K {
impl<K: Resource> Lookup for K {
type DynamicType = K::DynamicType;

fn kind(dyntype: &Self::DynamicType) -> Cow<'_, str> {
Expand Down Expand Up @@ -121,7 +121,7 @@ impl<K: Resource> ToObjectRef for K {
/// );
/// ```
#[non_exhaustive]
pub struct ObjectRef<K: ToObjectRef + ?Sized> {
pub struct ObjectRef<K: Lookup + ?Sized> {
pub dyntype: K::DynamicType,
/// The name of the object
pub name: String,
Expand Down Expand Up @@ -157,7 +157,7 @@ pub struct Extra {
pub uid: Option<String>,
}

impl<K: ToObjectRef> ObjectRef<K>
impl<K: Lookup> ObjectRef<K>
where
K::DynamicType: Default,
{
Expand All @@ -169,13 +169,13 @@ where
#[must_use]
pub fn from_obj(obj: &K) -> Self
where
K: ToObjectRef,
K: Lookup,
{
obj.to_object_ref(Default::default())
}
}

impl<K: ToObjectRef> ObjectRef<K> {
impl<K: Lookup> ObjectRef<K> {
#[must_use]
pub fn new_with(name: &str, dyntype: K::DynamicType) -> Self {
Self {
Expand All @@ -196,7 +196,7 @@ impl<K: ToObjectRef> ObjectRef<K> {
#[must_use]
pub fn from_obj_with(obj: &K, dyntype: K::DynamicType) -> Self
where
K: ToObjectRef,
K: Lookup,
{
obj.to_object_ref(dyntype)
}
Expand Down Expand Up @@ -230,7 +230,7 @@ impl<K: ToObjectRef> ObjectRef<K> {
/// Note that no checking is done on whether this conversion makes sense. For example, every `Service`
/// has a corresponding `Endpoints`, but it wouldn't make sense to convert a `Pod` into a `Deployment`.
#[must_use]
pub fn into_kind_unchecked<K2: ToObjectRef>(self, dt2: K2::DynamicType) -> ObjectRef<K2> {
pub fn into_kind_unchecked<K2: Lookup>(self, dt2: K2::DynamicType) -> ObjectRef<K2> {
ObjectRef {
dyntype: dt2,
name: self.name,
Expand All @@ -255,7 +255,7 @@ impl<K: ToObjectRef> ObjectRef<K> {
}
}

impl<K: ToObjectRef> From<ObjectRef<K>> for ObjectReference {
impl<K: Lookup> From<ObjectRef<K>> for ObjectReference {
fn from(val: ObjectRef<K>) -> Self {
let ObjectRef {
dyntype: dt,
Expand All @@ -278,7 +278,7 @@ impl<K: ToObjectRef> From<ObjectRef<K>> for ObjectReference {
}
}

impl<K: ToObjectRef> Display for ObjectRef<K> {
impl<K: Lookup> Display for ObjectRef<K> {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
write!(
f,
Expand Down
14 changes: 7 additions & 7 deletions kube-runtime/src/reflector/store.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use super::{ObjectRef, ToObjectRef};
use super::{ObjectRef, Lookup};
use crate::{
utils::delayed_init::{self, DelayedInit},
watcher,
Expand All @@ -16,7 +16,7 @@ type Cache<K> = Arc<RwLock<AHashMap<ObjectRef<K>, Arc<K>>>>;
/// This is exclusive since it's not safe to share a single `Store` between multiple reflectors.
/// In particular, `Restarted` events will clobber the state of other connected reflectors.
#[derive(Debug)]
pub struct Writer<K: 'static + ToObjectRef>
pub struct Writer<K: 'static + Lookup>
where
K::DynamicType: Eq + Hash,
{
Expand All @@ -26,7 +26,7 @@ where
ready_rx: Arc<DelayedInit<()>>,
}

impl<K: 'static + ToObjectRef + Clone> Writer<K>
impl<K: 'static + Lookup + Clone> Writer<K>
where
K::DynamicType: Eq + Hash + Clone,
{
Expand Down Expand Up @@ -85,7 +85,7 @@ where
}
impl<K> Default for Writer<K>
where
K: ToObjectRef + Clone + 'static,
K: Lookup + Clone + 'static,
K::DynamicType: Default + Eq + Hash + Clone,
{
fn default() -> Self {
Expand All @@ -101,7 +101,7 @@ where
/// use `Writer::as_reader()` instead.
#[derive(Derivative)]
#[derivative(Debug(bound = "K: Debug, K::DynamicType: Debug"), Clone)]
pub struct Store<K: 'static + ToObjectRef>
pub struct Store<K: 'static + Lookup>
where
K::DynamicType: Hash + Eq,
{
Expand All @@ -113,7 +113,7 @@ where
#[error("writer was dropped before store became ready")]
pub struct WriterDropped(delayed_init::InitDropped);

impl<K: 'static + Clone + ToObjectRef> Store<K>
impl<K: 'static + Clone + Lookup> Store<K>
where
K::DynamicType: Eq + Hash + Clone,
{
Expand Down Expand Up @@ -195,7 +195,7 @@ where
#[must_use]
pub fn store<K>() -> (Store<K>, Writer<K>)
where
K: ToObjectRef + Clone + 'static,
K: Lookup + Clone + 'static,
K::DynamicType: Eq + Hash + Clone + Default,
{
let w = Writer::<K>::default();
Expand Down

0 comments on commit 57e141e

Please sign in to comment.