diff --git a/kube-runtime/src/controller/mod.rs b/kube-runtime/src/controller/mod.rs index e2f83f5fc..342e6a5e7 100644 --- a/kube-runtime/src/controller/mod.rs +++ b/kube-runtime/src/controller/mod.rs @@ -66,7 +66,6 @@ where S: TryStream, I: IntoIterator>, K: Meta, - ::Family: Debug + Eq + Hash + Clone, { stream .map_ok(move |obj| stream::iter(mapper(obj).into_iter().map(Ok))) @@ -74,11 +73,11 @@ where } /// Enqueues the object itself for reconciliation -pub fn trigger_self(stream: S, family: F) -> impl Stream, S::Error>> +pub fn trigger_self(stream: S, family: K::Family) -> impl Stream, S::Error>> where - S: TryStream, - S::Ok: Meta, - F: Debug + Eq + Hash + Clone, + S: TryStream, + K: Meta, + K::Family: Clone, { trigger_with(stream, move |obj| { Some(ObjectRef::from_obj_with(&obj, family.clone())) @@ -86,17 +85,15 @@ where } /// Enqueues any owners of type `KOwner` for reconciliation -pub fn trigger_owners( +pub fn trigger_owners( stream: S, - // family: F, - owner_family: FOwner, + owner_family: KOwner::Family, ) -> impl Stream, S::Error>> where S: TryStream, - S::Ok: Meta, - F: Debug + Eq + Hash + Clone, - KOwner: Meta, - FOwner: Debug + Eq + Hash + Clone, + S::Ok: Meta, + KOwner: Meta, + KOwner::Family: Clone, { trigger_with(stream, move |obj| { let meta = obj.meta().clone(); @@ -158,7 +155,7 @@ pub fn applier( ) -> impl Stream, ReconcilerAction), Error>> where K: Clone + Meta + 'static, - ::Family: Debug + Eq + Hash + Clone + Unpin, + K::Family: Debug + Eq + Hash + Clone + Unpin, ReconcilerFut: TryFuture + Unpin, ReconcilerFut::Error: std::error::Error + 'static, QueueStream: TryStream>, @@ -296,7 +293,7 @@ where pub struct Controller where K: Clone + Meta + Debug + 'static, - ::Family: Debug + Eq + Hash + Clone, + K::Family: Eq + Hash, { // NB: Need to Unpin for stream::select_all // TODO: get an arbitrary std::error::Error in here? @@ -308,7 +305,7 @@ where impl Controller where K: Clone + Meta + DeserializeOwned + Debug + Send + Sync + 'static, - ::Family: Debug + Eq + Hash + Clone + Default, + K::Family: Eq + Hash + Clone + Default, { /// Create a Controller on a type `K` /// @@ -323,7 +320,7 @@ where impl Controller where K: Clone + Meta + DeserializeOwned + Debug + Send + Sync + 'static, - ::Family: Debug + Eq + Hash + Clone, + K::Family: Eq + Hash + Clone, { /// Create a Controller on a type `K` /// @@ -368,7 +365,7 @@ where lp: ListParams, ) -> Self where - ::Family: Debug + Eq + Hash + Clone, + Child::Family: Debug + Eq + Hash + Clone, { let child_watcher = trigger_owners(try_flatten_touched(watcher(api, lp)), self.family.clone()); self.selector.push(child_watcher.boxed()); @@ -407,8 +404,7 @@ where context: Context, ) -> impl Stream, ReconcilerAction), Error>> where - K: Clone + Meta + 'static, - ::Family: Eq + Hash + Clone + Unpin, + K::Family: Debug + Unpin, ReconcilerFut: TryFuture + Send + 'static, ReconcilerFut::Error: std::error::Error + Send + 'static, { diff --git a/kube-runtime/src/lib.rs b/kube-runtime/src/lib.rs index c21607ff3..c640b4d6c 100644 --- a/kube-runtime/src/lib.rs +++ b/kube-runtime/src/lib.rs @@ -15,6 +15,7 @@ #![allow(clippy::pub_enum_variant_names)] // Triggered by many derive macros (kube-derive, derivative) #![allow(clippy::default_trait_access)] +#![allow(clippy::type_repetition_in_bounds)] pub mod controller; pub mod reflector; diff --git a/kube-runtime/src/reflector/mod.rs b/kube-runtime/src/reflector/mod.rs index 1e3694ea6..1fe2437d0 100644 --- a/kube-runtime/src/reflector/mod.rs +++ b/kube-runtime/src/reflector/mod.rs @@ -7,7 +7,7 @@ pub use self::object_ref::ObjectRef; use crate::watcher; use futures::{Stream, TryStreamExt}; use kube::api::Meta; -use std::{fmt::Debug, hash::Hash}; +use std::hash::Hash; pub use store::Store; /// Caches objects from `watcher::Event`s to a local `Store` @@ -19,7 +19,7 @@ pub use store::Store; pub fn reflector(mut store: store::Writer, stream: W) -> impl Stream where K: Meta + Clone, - ::Family: Debug + Eq + Hash + Clone, + K::Family: Eq + Hash + Clone, W: Stream>>, { stream.inspect_ok(move |event| store.apply_watcher_event(event)) diff --git a/kube-runtime/src/reflector/object_ref.rs b/kube-runtime/src/reflector/object_ref.rs index 5e2a3fe33..189a99649 100644 --- a/kube-runtime/src/reflector/object_ref.rs +++ b/kube-runtime/src/reflector/object_ref.rs @@ -7,7 +7,13 @@ use std::{ }; #[derive(Derivative)] -#[derivative(Debug, PartialEq, Eq, Hash, Clone)] +#[derivative( + Debug(bound = "K::Family: Debug"), + PartialEq(bound = "K::Family: PartialEq"), + Eq(bound = "K::Family: Eq"), + Hash(bound = "K::Family: Hash"), + Clone(bound = "K::Family: Clone") +)] /// A typed and namedspaced (if relevant) reference to a Kubernetes object /// /// `K` may be either the object type or `DynamicObject`, in which case the @@ -22,10 +28,7 @@ use std::{ /// ObjectRef::::new("a").erase(), /// ); /// ``` -pub struct ObjectRef -where - ::Family: Debug + Eq + Hash + Clone, -{ +pub struct ObjectRef { family: K::Family, /// The name of the object pub name: String, @@ -45,7 +48,7 @@ where impl ObjectRef where - ::Family: Debug + Eq + Hash + Clone + Default, + K::Family: Default, { #[must_use] pub fn new(name: &str) -> Self { @@ -61,10 +64,7 @@ where } } -impl ObjectRef -where - ::Family: Debug + Eq + Hash + Clone, -{ +impl ObjectRef { #[must_use] pub fn new_with(name: &str, family: K::Family) -> Self { Self { @@ -117,10 +117,7 @@ where /// 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(self, f2: K2::Family) -> ObjectRef - where - ::Family: Debug + Eq + Hash + Clone, - { + pub fn into_kind_unchecked(self, f2: K2::Family) -> ObjectRef { ObjectRef { family: f2, name: self.name, @@ -141,10 +138,7 @@ where } } -impl Display for ObjectRef -where - ::Family: Debug + Eq + Hash + Clone, -{ +impl Display for ObjectRef { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { write!( f, diff --git a/kube-runtime/src/reflector/store.rs b/kube-runtime/src/reflector/store.rs index f1f2afd36..a94db8d84 100644 --- a/kube-runtime/src/reflector/store.rs +++ b/kube-runtime/src/reflector/store.rs @@ -10,10 +10,10 @@ use std::{collections::HashMap, fmt::Debug, hash::Hash, sync::Arc}; /// 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, Derivative)] -#[derivative(Default(bound = "::Family: Default"))] +#[derivative(Default(bound = "K::Family: Default"))] pub struct Writer where - ::Family: Debug + Eq + Hash + Clone, + K::Family: Eq + Hash, { store: Arc, K>>, family: K::Family, @@ -21,7 +21,7 @@ where impl Writer where - ::Family: Debug + Eq + Hash + Clone, + K::Family: Eq + Hash, { /// Creates a new Writer with the specified family. /// @@ -46,7 +46,10 @@ where } /// Applies a single watcher event to the store - pub fn apply_watcher_event(&mut self, event: &watcher::Event) { + pub fn apply_watcher_event(&mut self, event: &watcher::Event) + where + K::Family: Clone, + { match event { watcher::Event::Applied(obj) => { self.store @@ -77,18 +80,18 @@ where /// /// Cannot be constructed directly since one writer handle is required, /// use `Writer::as_reader()` instead. -#[derive(Debug, Derivative)] -#[derivative(Clone)] +#[derive(Derivative)] +#[derivative(Debug(bound = "K: Debug, K::Family: Debug"), Clone)] pub struct Store where - ::Family: Debug + Eq + Hash + Clone, + K::Family: Hash + Eq, { store: Arc, K>>, } impl Store where - ::Family: Debug + Eq + Hash + Clone, + K::Family: Eq + Hash + Clone, { /// Retrieve a `clone()` of the entry referred to by `key`, if it is in the cache. ///