diff --git a/tower/CHANGELOG.md b/tower/CHANGELOG.md index 840d3745d..0671f77e5 100644 --- a/tower/CHANGELOG.md +++ b/tower/CHANGELOG.md @@ -7,7 +7,20 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 # Unreleased -- None. +### Fixed + +- **balance**: Remove redundant `Req: Clone` bound from `Clone` impls + for `MakeBalance`, and `MakeBalanceLayer` ([#607]) +- **balance**: Remove redundant `Req: Debug` bound from `Debug` impls + for `MakeBalance`, `MakeFuture`, `Balance`, and `Pool` ([#607]) +- **ready-cache**: Remove redundant `Req: Debug` bound from `Debug` impl + for `ReadyCache` ([#607]) +- **steer**: Remove redundant `Req: Debug` bound from `Debug` impl + for `Steer` ([#607]) +- **util**: Remove redundant `F: Clone` bound + from `ServiceExt::map_request` ([#607]) + +[#607]: https://github.com/tower-rs/tower/pull/607 # 0.4.10 (October 19, 2021) @@ -19,7 +32,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 # 0.4.9 (October 13, 2021) -- Migrate to pin-project-lite ([#595]) +- Migrate to [pin-project-lite] ([#595]) - **builder**: Implement `Layer` for `ServiceBuilder` ([#600]) - **builder**: Add `ServiceBuilder::and_then` analogous to `ServiceExt::and_then` ([#601]) diff --git a/tower/src/balance/p2c/layer.rs b/tower/src/balance/p2c/layer.rs index 90ff8cf3f..ce59c6e06 100644 --- a/tower/src/balance/p2c/layer.rs +++ b/tower/src/balance/p2c/layer.rs @@ -18,7 +18,6 @@ use tower_layer::Layer; /// [`Discover`]: crate::discover::Discover /// [`MakeService`]: crate::MakeService /// [`Service`]: crate::Service -#[derive(Clone)] pub struct MakeBalanceLayer { _marker: PhantomData, } @@ -38,6 +37,14 @@ impl Default for MakeBalanceLayer { } } +impl Clone for MakeBalanceLayer { + fn clone(&self) -> Self { + Self { + _marker: PhantomData, + } + } +} + impl Layer for MakeBalanceLayer { type Service = MakeBalance; diff --git a/tower/src/balance/p2c/make.rs b/tower/src/balance/p2c/make.rs index 84ea92577..538d70360 100644 --- a/tower/src/balance/p2c/make.rs +++ b/tower/src/balance/p2c/make.rs @@ -5,6 +5,7 @@ use pin_project_lite::pin_project; use std::hash::Hash; use std::marker::PhantomData; use std::{ + fmt, future::Future, pin::Pin, task::{Context, Poll}, @@ -23,7 +24,6 @@ use tower_service::Service; /// [`MakeService`]: crate::MakeService /// [`Discover`]: crate::discover::Discover /// [`Balance`]: crate::balance::p2c::Balance -#[derive(Clone, Debug)] pub struct MakeBalance { inner: S, _marker: PhantomData, @@ -33,7 +33,6 @@ pin_project! { /// A [`Balance`] in the making. /// /// [`Balance`]: crate::balance::p2c::Balance - #[derive(Debug)] pub struct MakeFuture { #[pin] inner: F, @@ -51,6 +50,18 @@ impl MakeBalance { } } +impl Clone for MakeBalance +where + S: Clone, +{ + fn clone(&self) -> Self { + Self { + inner: self.inner.clone(), + _marker: PhantomData, + } + } +} + impl Service for MakeBalance where S: Service, @@ -75,6 +86,16 @@ where } } +impl fmt::Debug for MakeBalance +where + S: fmt::Debug, +{ + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + let Self { inner, _marker } = self; + f.debug_struct("MakeBalance").field("inner", inner).finish() + } +} + impl Future for MakeFuture where F: Future>, @@ -92,3 +113,13 @@ where Poll::Ready(Ok(svc)) } } + +impl fmt::Debug for MakeFuture +where + F: fmt::Debug, +{ + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + let Self { inner, _marker } = self; + f.debug_struct("MakeFuture").field("inner", inner).finish() + } +} diff --git a/tower/src/balance/p2c/service.rs b/tower/src/balance/p2c/service.rs index d12e87323..f85d2419c 100644 --- a/tower/src/balance/p2c/service.rs +++ b/tower/src/balance/p2c/service.rs @@ -49,7 +49,6 @@ where D: fmt::Debug, D::Key: Hash + fmt::Debug, D::Service: fmt::Debug, - Req: fmt::Debug, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Balance") @@ -63,7 +62,6 @@ pin_project! { /// A Future that becomes satisfied when an `S`-typed service is ready. /// /// May fail due to cancelation, i.e., if [`Discover`] removes the service from the service set. - #[derive(Debug)] struct UnreadyService { key: Option, #[pin] @@ -315,3 +313,23 @@ impl, Req> Future for UnreadyService { } } } + +impl fmt::Debug for UnreadyService +where + K: fmt::Debug, + S: fmt::Debug, +{ + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + let Self { + key, + cancel, + service, + _req, + } = self; + f.debug_struct("UnreadyService") + .field("key", key) + .field("cancel", cancel) + .field("service", service) + .finish() + } +} diff --git a/tower/src/balance/pool/mod.rs b/tower/src/balance/pool/mod.rs index f32d25fe0..ab43936fe 100644 --- a/tower/src/balance/pool/mod.rs +++ b/tower/src/balance/pool/mod.rs @@ -318,7 +318,6 @@ where MS::Error: Into, Target: Clone + fmt::Debug, MS::Service: fmt::Debug, - Request: fmt::Debug, { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_struct("Pool") diff --git a/tower/src/buffer/layer.rs b/tower/src/buffer/layer.rs index d68d3e009..aadc938bd 100644 --- a/tower/src/buffer/layer.rs +++ b/tower/src/buffer/layer.rs @@ -67,7 +67,7 @@ impl Clone for BufferLayer { fn clone(&self) -> Self { Self { bound: self.bound, - _p: self._p, + _p: PhantomData, } } } diff --git a/tower/src/ready_cache/cache.rs b/tower/src/ready_cache/cache.rs index 6cdaca85f..f0fc1d053 100644 --- a/tower/src/ready_cache/cache.rs +++ b/tower/src/ready_cache/cache.rs @@ -5,6 +5,7 @@ use futures_core::Stream; use futures_util::stream::FuturesUnordered; pub use indexmap::Equivalent; use indexmap::IndexMap; +use std::fmt; use std::future::Future; use std::hash::Hash; use std::pin::Pin; @@ -53,7 +54,6 @@ use tracing::{debug, trace}; /// service. In such a case, it should be noted that calls to /// [`ReadyCache::poll_pending`] and [`ReadyCache::evict`] may perturb the order of /// the ready set, so any cached indexes should be discarded after such a call. -#[derive(Debug)] pub struct ReadyCache where K: Eq + Hash, @@ -88,7 +88,6 @@ enum PendingError { /// A [`Future`] that becomes satisfied when an `S`-typed service is ready. /// /// May fail due to cancelation, i.e. if the service is evicted from the balancer. -#[derive(Debug)] struct Pending { key: Option, cancel: Option, @@ -112,6 +111,25 @@ where } } +impl fmt::Debug for ReadyCache +where + K: fmt::Debug + Eq + Hash, + S: fmt::Debug, +{ + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + let Self { + pending, + pending_cancel_txs, + ready, + } = self; + f.debug_struct("ReadyCache") + .field("pending", pending) + .field("pending_cancel_txs", pending_cancel_txs) + .field("ready", ready) + .finish() + } +} + impl ReadyCache where K: Eq + Hash, @@ -418,3 +436,23 @@ where } } } + +impl fmt::Debug for Pending +where + K: fmt::Debug, + S: fmt::Debug, +{ + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + let Self { + key, + cancel, + ready, + _pd, + } = self; + f.debug_struct("Pending") + .field("key", key) + .field("cancel", cancel) + .field("ready", ready) + .finish() + } +} diff --git a/tower/src/steer/mod.rs b/tower/src/steer/mod.rs index 53ba3bac1..f9d2565c0 100644 --- a/tower/src/steer/mod.rs +++ b/tower/src/steer/mod.rs @@ -69,7 +69,7 @@ //! # } //! ``` use std::task::{Context, Poll}; -use std::{collections::VecDeque, marker::PhantomData}; +use std::{collections::VecDeque, fmt, marker::PhantomData}; use tower_service::Service; /// This is how callers of [`Steer`] tell it which `Service` a `Req` corresponds to. @@ -104,7 +104,6 @@ where /// requests) will prevent head-of-line blocking in [`Steer`]. /// /// [`Buffer`]: crate::buffer::Buffer -#[derive(Debug)] pub struct Steer { router: F, services: Vec, @@ -180,3 +179,23 @@ where } } } + +impl fmt::Debug for Steer +where + S: fmt::Debug, + F: fmt::Debug, +{ + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + let Self { + router, + services, + not_ready, + _phantom, + } = self; + f.debug_struct("Steer") + .field("router", router) + .field("services", services) + .field("not_ready", not_ready) + .finish() + } +} diff --git a/tower/src/util/mod.rs b/tower/src/util/mod.rs index 15cd0735b..901034ae4 100644 --- a/tower/src/util/mod.rs +++ b/tower/src/util/mod.rs @@ -604,7 +604,7 @@ pub trait ServiceExt: tower_service::Service { fn map_request(self, f: F) -> MapRequest where Self: Sized, - F: FnMut(NewRequest) -> Request + Clone, + F: FnMut(NewRequest) -> Request, { MapRequest::new(self, f) }