Skip to content

Commit

Permalink
tower: prepare to release 0.4.11 (#618)
Browse files Browse the repository at this point in the history
* tower: prepare to release 0.4.11

Added

- **util**: Add `CloneBoxService` which is a `Clone + Send` boxed `Service` ([#615])
- **util**: Add `ServiceExt::boxed` and `ServiceExt::clone_boxed` for applying the
  `BoxService` and `CloneBoxService` middleware ([#616])
- **builder**: Add `ServiceBuilder::boxed` and `ServiceBuilder::clone_boxed` for
  applying `BoxService` and `CloneBoxService` layers ([#616])

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])
- **docs**: Fix `doc(cfg(...))` attributes
  of `PeakEwmaDiscover`, and `PendingRequestsDiscover` ([#610])
- **util**: Remove unnecessary `Debug` bounds from `impl Debug for BoxService` ([#617])
- **util**: Remove unnecessary `Debug` bounds from `impl Debug for UnsyncBoxService` ([#617])

[#607]: #607
[#610]: #610
[#616]: #616
[#617]: #617
[#615]: #615

* sorting

* Rename `CloneBoxService` to `BoxCloneService`

* formatting

* also update changelog
  • Loading branch information
davidpdrsn committed Nov 18, 2021
1 parent 4d80f7e commit 7674109
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 46 deletions.
26 changes: 17 additions & 9 deletions tower/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,23 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

# Unreleased

- **util**: Add `CloneBoxService` which is a `Clone + Send` boxed `Service`.
- **util:** Add `ServiceExt::boxed` and `ServiceExt::clone_boxed` for applying the
`BoxService` and `CloneBoxService` middleware.
- **builder:** Add `ServiceBuilder::boxed` and `ServiceBuilder::clone_boxed` for
applying `BoxService` and `CloneBoxService` layers.
- **util**: Remove unnecessary `Debug` bounds from `impl Debug for BoxService`.
- **util**: Remove unnecessary `Debug` bounds from `impl Debug for UnsyncBoxService`.
- None.

# 0.4.11 (November 18, 2021)

### Added

- **util**: Add `BoxCloneService` which is a `Clone + Send` boxed `Service` ([#615])
- **util**: Add `ServiceExt::boxed` and `ServiceExt::boxed_clone` for applying the
`BoxService` and `BoxCloneService` middleware ([#616])
- **builder**: Add `ServiceBuilder::boxed` and `ServiceBuilder::boxed_clone` for
applying `BoxService` and `BoxCloneService` layers ([#616])

### Fixed

- **util**: Remove redundant `F: Clone` bound from `ServiceExt::map_request` ([#607])
- **util**: Remove unnecessary `Debug` bounds from `impl Debug for BoxService` ([#617])
- **util**: Remove unnecessary `Debug` bounds from `impl Debug for UnsyncBoxService` ([#617])
- **balance**: Remove redundant `Req: Clone` bound from `Clone` impls
for `MakeBalance`, and `MakeBalanceLayer` ([#607])
- **balance**: Remove redundant `Req: Debug` bound from `Debug` impls
Expand All @@ -25,13 +32,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
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])
- **docs**: Fix `doc(cfg(...))` attributes
of `PeakEwmaDiscover`, and `PendingRequestsDiscover` ([#610])

[#607]: https://github.com/tower-rs/tower/pull/607
[#610]: https://github.com/tower-rs/tower/pull/610
[#615]: https://github.com/tower-rs/tower/pull/615
[#616]: https://github.com/tower-rs/tower/pull/616
[#617]: https://github.com/tower-rs/tower/pull/617

# 0.4.10 (October 19, 2021)

Expand Down
4 changes: 2 additions & 2 deletions tower/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ name = "tower"
# - README.md
# - Update CHANGELOG.md.
# - Create "vX.X.X" git tag.
version = "0.4.10"
version = "0.4.11"
authors = ["Tower Maintainers <team@tower-rs.com>"]
license = "MIT"
readme = "README.md"
repository = "https://github.com/tower-rs/tower"
homepage = "https://github.com/tower-rs/tower"
documentation = "https://docs.rs/tower/0.4.10"
documentation = "https://docs.rs/tower/0.4.11"
description = """
Tower is a library of modular and reusable components for building robust
clients and servers.
Expand Down
20 changes: 10 additions & 10 deletions tower/src/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -745,17 +745,17 @@ impl<L> ServiceBuilder<L> {
self.layer(crate::util::BoxService::layer())
}

/// This wraps the inner service with the [`Layer`] returned by [`CloneBoxService::layer()`].
/// This wraps the inner service with the [`Layer`] returned by [`BoxCloneService::layer()`].
///
/// This is similar to the [`boxed`] method, but it requires that `Self` implement
/// [`Clone`], and the returned boxed service implements [`Clone`].
///
/// See [`CloneBoxService`] for more details.
/// See [`BoxCloneService`] for more details.
///
/// # Example
///
/// ```
/// use tower::{Service, ServiceBuilder, BoxError, util::CloneBoxService};
/// use tower::{Service, ServiceBuilder, BoxError, util::BoxCloneService};
/// use std::time::Duration;
/// #
/// # struct Request;
Expand All @@ -764,8 +764,8 @@ impl<L> ServiceBuilder<L> {
/// # fn new() -> Self { Self }
/// # }
///
/// let service: CloneBoxService<Request, Response, BoxError> = ServiceBuilder::new()
/// .clone_boxed()
/// let service: BoxCloneService<Request, Response, BoxError> = ServiceBuilder::new()
/// .boxed_clone()
/// .load_shed()
/// .concurrency_limit(64)
/// .timeout(Duration::from_secs(10))
Expand All @@ -780,19 +780,19 @@ impl<L> ServiceBuilder<L> {
/// # where S: Service<R> { svc }
/// ```
///
/// [`CloneBoxService::layer()`]: crate::util::CloneBoxService::layer()
/// [`CloneBoxService`]: crate::util::CloneBoxService
/// [`BoxCloneService::layer()`]: crate::util::BoxCloneService::layer()
/// [`BoxCloneService`]: crate::util::BoxCloneService
/// [`boxed`]: Self::boxed
#[cfg(feature = "util")]
#[cfg_attr(docsrs, doc(cfg(feature = "util")))]
pub fn clone_boxed<S, R>(
pub fn boxed_clone<S, R>(
self,
) -> ServiceBuilder<
Stack<
tower_layer::LayerFn<
fn(
L::Service,
) -> crate::util::CloneBoxService<
) -> crate::util::BoxCloneService<
R,
<L::Service as Service<R>>::Response,
<L::Service as Service<R>>::Error,
Expand All @@ -806,7 +806,7 @@ impl<L> ServiceBuilder<L> {
L::Service: Service<R> + Clone + Send + 'static,
<L::Service as Service<R>>::Future: Send + 'static,
{
self.layer(crate::util::CloneBoxService::layer())
self.layer(crate::util::BoxCloneService::layer())
}
}

Expand Down
2 changes: 1 addition & 1 deletion tower/src/lib.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#![doc(html_root_url = "https://docs.rs/tower/0.4.10")]
#![doc(html_root_url = "https://docs.rs/tower/0.4.11")]
#![warn(
missing_debug_implementations,
missing_docs,
Expand Down
2 changes: 1 addition & 1 deletion tower/src/util/boxed/sync.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ use std::{
/// response future to be [`Send`].
///
/// If you need a boxed [`Service`] that implements [`Clone`] consider using
/// [`CloneBoxService`](crate::util::CloneBoxService).
/// [`BoxCloneService`](crate::util::BoxCloneService).
///
/// See module level documentation for more details.
pub struct BoxService<T, U, E> {
Expand Down
26 changes: 13 additions & 13 deletions tower/src/util/clone_boxed.rs → tower/src/util/boxed_clone.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use tower_service::Service;

/// A [`Clone`] + [`Send`] boxed [`Service`].
///
/// [`CloneBoxService`] turns a service into a trait object, allowing the
/// [`BoxCloneService`] turns a service into a trait object, allowing the
/// response future type to be dynamic, and allowing the service to be cloned.
///
/// This is similar to [`BoxService`](super::BoxService) except the resulting
Expand All @@ -18,7 +18,7 @@ use tower_service::Service;
/// # Example
///
/// ```
/// use tower::{Service, ServiceBuilder, BoxError, util::CloneBoxService};
/// use tower::{Service, ServiceBuilder, BoxError, util::BoxCloneService};
/// use std::time::Duration;
/// #
/// # struct Request;
Expand All @@ -45,8 +45,8 @@ use tower_service::Service;
/// });
/// # let service = assert_service(service);
///
/// // `CloneBoxService` will erase the type so it's nameable
/// let service: CloneBoxService<Request, Response, BoxError> = CloneBoxService::new(service);
/// // `BoxCloneService` will erase the type so it's nameable
/// let service: BoxCloneService<Request, Response, BoxError> = BoxCloneService::new(service);
/// # let service = assert_service(service);
///
/// // And we can still clone the service
Expand All @@ -55,25 +55,25 @@ use tower_service::Service;
/// # fn assert_service<S, R>(svc: S) -> S
/// # where S: Service<R> { svc }
/// ```
pub struct CloneBoxService<T, U, E>(
pub struct BoxCloneService<T, U, E>(
Box<
dyn CloneService<T, Response = U, Error = E, Future = BoxFuture<'static, Result<U, E>>>
+ Send,
>,
);

impl<T, U, E> CloneBoxService<T, U, E> {
/// Create a new `CloneBoxService`.
impl<T, U, E> BoxCloneService<T, U, E> {
/// Create a new `BoxCloneService`.
pub fn new<S>(inner: S) -> Self
where
S: Service<T, Response = U, Error = E> + Clone + Send + 'static,
S::Future: Send + 'static,
{
let inner = inner.map_future(|f| Box::pin(f) as _);
CloneBoxService(Box::new(inner))
BoxCloneService(Box::new(inner))
}

/// Returns a [`Layer`] for wrapping a [`Service`] in a [`CloneBoxService`]
/// Returns a [`Layer`] for wrapping a [`Service`] in a [`BoxCloneService`]
/// middleware.
///
/// [`Layer`]: crate::Layer
Expand All @@ -86,7 +86,7 @@ impl<T, U, E> CloneBoxService<T, U, E> {
}
}

impl<T, U, E> Service<T> for CloneBoxService<T, U, E> {
impl<T, U, E> Service<T> for BoxCloneService<T, U, E> {
type Response = U;
type Error = E;
type Future = BoxFuture<'static, Result<U, E>>;
Expand All @@ -102,7 +102,7 @@ impl<T, U, E> Service<T> for CloneBoxService<T, U, E> {
}
}

impl<T, U, E> Clone for CloneBoxService<T, U, E> {
impl<T, U, E> Clone for BoxCloneService<T, U, E> {
fn clone(&self) -> Self {
Self(self.0.clone_box())
}
Expand All @@ -129,8 +129,8 @@ where
}
}

impl<T, U, E> fmt::Debug for CloneBoxService<T, U, E> {
impl<T, U, E> fmt::Debug for BoxCloneService<T, U, E> {
fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result {
fmt.debug_struct("CloneBoxService").finish()
fmt.debug_struct("BoxCloneService").finish()
}
}
20 changes: 10 additions & 10 deletions tower/src/util/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

mod and_then;
mod boxed;
mod boxed_clone;
mod call_all;
mod clone_boxed;
mod either;

mod future_service;
Expand All @@ -23,7 +23,7 @@ mod then;
pub use self::{
and_then::{AndThen, AndThenLayer},
boxed::{BoxLayer, BoxService, UnsyncBoxService},
clone_boxed::CloneBoxService,
boxed_clone::BoxCloneService,
either::Either,
future_service::{future_service, FutureService},
map_err::{MapErr, MapErrLayer},
Expand Down Expand Up @@ -958,7 +958,7 @@ pub trait ServiceExt<Request>: tower_service::Service<Request> {
///
/// See [`BoxService`] for more details.
///
/// If `Self` implements the [`Clone`] trait, the [`clone_boxed`] method
/// If `Self` implements the [`Clone`] trait, the [`boxed_clone`] method
/// can be used instead, to produce a boxed service which will also
/// implement [`Clone`].
///
Expand Down Expand Up @@ -993,7 +993,7 @@ pub trait ServiceExt<Request>: tower_service::Service<Request> {
/// ```
///
/// [`Service`]: crate::Service
/// [`clone_boxed`]: Self::clone_boxed
/// [`boxed_clone`]: Self::boxed_clone
fn boxed(self) -> BoxService<Request, Self::Response, Self::Error>
where
Self: Sized + Send + 'static,
Expand All @@ -1006,12 +1006,12 @@ pub trait ServiceExt<Request>: tower_service::Service<Request> {
///
/// This is similar to the [`boxed`] method, but it requires that `Self` implement
/// [`Clone`], and the returned boxed service implements [`Clone`].
/// See [`CloneBoxService`] for more details.
/// See [`BoxCloneService`] for more details.
///
/// # Example
///
/// ```
/// use tower::{Service, ServiceExt, BoxError, service_fn, util::CloneBoxService};
/// use tower::{Service, ServiceExt, BoxError, service_fn, util::BoxCloneService};
/// #
/// # struct Request;
/// # struct Response;
Expand All @@ -1023,7 +1023,7 @@ pub trait ServiceExt<Request>: tower_service::Service<Request> {
/// Ok::<_, BoxError>(Response::new())
/// });
///
/// let service: CloneBoxService<Request, Response, BoxError> = service
/// let service: BoxCloneService<Request, Response, BoxError> = service
/// .map_request(|req| {
/// println!("received request");
/// req
Expand All @@ -1032,7 +1032,7 @@ pub trait ServiceExt<Request>: tower_service::Service<Request> {
/// println!("response produced");
/// res
/// })
/// .clone_boxed();
/// .boxed_clone();
///
/// // The boxed service can still be cloned.
/// service.clone();
Expand All @@ -1043,12 +1043,12 @@ pub trait ServiceExt<Request>: tower_service::Service<Request> {
///
/// [`Service`]: crate::Service
/// [`boxed`]: Self::boxed
fn clone_boxed(self) -> CloneBoxService<Request, Self::Response, Self::Error>
fn boxed_clone(self) -> BoxCloneService<Request, Self::Response, Self::Error>
where
Self: Clone + Sized + Send + 'static,
Self::Future: Send + 'static,
{
CloneBoxService::new(self)
BoxCloneService::new(self)
}
}

Expand Down

0 comments on commit 7674109

Please sign in to comment.