Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions tower/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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])
Expand Down
9 changes: 8 additions & 1 deletion tower/src/balance/p2c/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ use tower_layer::Layer;
/// [`Discover`]: crate::discover::Discover
/// [`MakeService`]: crate::MakeService
/// [`Service`]: crate::Service
#[derive(Clone)]
pub struct MakeBalanceLayer<D, Req> {
_marker: PhantomData<fn(D, Req)>,
}
Expand All @@ -38,6 +37,14 @@ impl<D, Req> Default for MakeBalanceLayer<D, Req> {
}
}

impl<D, Req> Clone for MakeBalanceLayer<D, Req> {
fn clone(&self) -> Self {
Self {
_marker: PhantomData,
}
}
}

impl<S, Req> Layer<S> for MakeBalanceLayer<S, Req> {
type Service = MakeBalance<S, Req>;

Expand Down
35 changes: 33 additions & 2 deletions tower/src/balance/p2c/make.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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<S, Req> {
inner: S,
_marker: PhantomData<fn(Req)>,
Expand All @@ -33,7 +33,6 @@ pin_project! {
/// A [`Balance`] in the making.
///
/// [`Balance`]: crate::balance::p2c::Balance
#[derive(Debug)]
pub struct MakeFuture<F, Req> {
#[pin]
inner: F,
Expand All @@ -51,6 +50,18 @@ impl<S, Req> MakeBalance<S, Req> {
}
}

impl<S, Req> Clone for MakeBalance<S, Req>
where
S: Clone,
{
fn clone(&self) -> Self {
Self {
inner: self.inner.clone(),
_marker: PhantomData,
}
}
}

impl<S, Target, Req> Service<Target> for MakeBalance<S, Req>
where
S: Service<Target>,
Expand All @@ -75,6 +86,16 @@ where
}
}

impl<S, Req> fmt::Debug for MakeBalance<S, Req>
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<F, T, E, Req> Future for MakeFuture<F, Req>
where
F: Future<Output = Result<T, E>>,
Expand All @@ -92,3 +113,13 @@ where
Poll::Ready(Ok(svc))
}
}

impl<F, Req> fmt::Debug for MakeFuture<F, Req>
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()
}
}
22 changes: 20 additions & 2 deletions tower/src/balance/p2c/service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand All @@ -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<K, S, Req> {
key: Option<K>,
#[pin]
Expand Down Expand Up @@ -315,3 +313,23 @@ impl<K, S: Service<Req>, Req> Future for UnreadyService<K, S, Req> {
}
}
}

impl<K, S, Req> fmt::Debug for UnreadyService<K, S, Req>
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()
}
}
1 change: 0 additions & 1 deletion tower/src/balance/pool/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -318,7 +318,6 @@ where
MS::Error: Into<crate::BoxError>,
Target: Clone + fmt::Debug,
MS::Service: fmt::Debug,
Request: fmt::Debug,
{
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
f.debug_struct("Pool")
Expand Down
2 changes: 1 addition & 1 deletion tower/src/buffer/layer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ impl<Request> Clone for BufferLayer<Request> {
fn clone(&self) -> Self {
Self {
bound: self.bound,
_p: self._p,
_p: PhantomData,
}
}
}
Expand Down
42 changes: 40 additions & 2 deletions tower/src/ready_cache/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<K, S, Req>
where
K: Eq + Hash,
Expand Down Expand Up @@ -88,7 +88,6 @@ enum PendingError<K, E> {
/// 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<K, S, Req> {
key: Option<K>,
cancel: Option<CancelRx>,
Expand All @@ -112,6 +111,25 @@ where
}
}

impl<K, S, Req> fmt::Debug for ReadyCache<K, S, Req>
where
K: fmt::Debug + Eq + Hash,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why is eq and hash required here?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe there's a K: Hash + Eq bound on the ReadyCache type, which is required because K is used as the key type to an IndexMap:

pub struct ReadyCache<K, S, Req>
where
K: 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<K, S, Req> ReadyCache<K, S, Req>
where
K: Eq + Hash,
Expand Down Expand Up @@ -418,3 +436,23 @@ where
}
}
}

impl<K, S, Req> fmt::Debug for Pending<K, S, Req>
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()
}
}
23 changes: 21 additions & 2 deletions tower/src/steer/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -104,7 +104,6 @@ where
/// requests) will prevent head-of-line blocking in [`Steer`].
///
/// [`Buffer`]: crate::buffer::Buffer
#[derive(Debug)]
pub struct Steer<S, F, Req> {
router: F,
services: Vec<S>,
Expand Down Expand Up @@ -180,3 +179,23 @@ where
}
}
}

impl<S, F, Req> fmt::Debug for Steer<S, F, Req>
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()
}
}
2 changes: 1 addition & 1 deletion tower/src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -604,7 +604,7 @@ pub trait ServiceExt<Request>: tower_service::Service<Request> {
fn map_request<F, NewRequest>(self, f: F) -> MapRequest<Self, F>
where
Self: Sized,
F: FnMut(NewRequest) -> Request + Clone,
F: FnMut(NewRequest) -> Request,
{
MapRequest::new(self, f)
}
Expand Down