Skip to content

Commit

Permalink
tower v0.5.2
Browse files Browse the repository at this point in the history
  • Loading branch information
jlizen committed Dec 19, 2024
1 parent a09fd97 commit 68c3b7e
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 1 deletion.
9 changes: 9 additions & 0 deletions tower/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,17 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

# 0.5.2

### Added

- **util**: Add `BoxCloneSyncService` which is a `Clone + Send + Sync` boxed `Service` ([#777])
- **util**: Add `BoxCloneSyncServiceLayer` which is a `Clone + Send + Sync` boxed `Layer` ([802])

# 0.5.1

### Fixed

- Fix minimum version of `tower-layer` dependency ([#787])

[#787]: https://github.com/tower-rs/tower/pull/787
Expand Down
2 changes: 1 addition & 1 deletion tower/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ name = "tower"
# - Update README.md
# - Update CHANGELOG.md.
# - Create "vX.X.X" git tag.
version = "0.5.1"
version = "0.5.2"
authors = ["Tower Maintainers <[email protected]>"]
license = "MIT"
readme = "README.md"
Expand Down
64 changes: 64 additions & 0 deletions tower/src/builder/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -789,6 +789,70 @@ impl<L> ServiceBuilder<L> {
{
self.layer(crate::util::BoxCloneService::layer())
}

/// This wraps the inner service with the [`Layer`] returned by [`BoxCloneSyncServiceLayer`].
///
/// This is similar to the [`boxed_clone`] method, but it requires that `Self` implement
/// [`Sync`], and the returned boxed service implements [`Sync`].
///
/// See [`BoxCloneSyncService`] for more details.
///
/// # Example
///
/// ```
/// use tower::{Service, ServiceBuilder, BoxError, util::BoxCloneSyncService};
/// use std::time::Duration;
/// #
/// # struct Request;
/// # struct Response;
/// # impl Response {
/// # fn new() -> Self { Self }
/// # }
///
/// let service: BoxCloneSyncService<Request, Response, BoxError> = ServiceBuilder::new()
/// .load_shed()
/// .concurrency_limit(64)
/// .timeout(Duration::from_secs(10))
/// .boxed_clone_sync()
/// .service_fn(|req: Request| async {
/// Ok::<_, BoxError>(Response::new())
/// });
/// # let service = assert_service(service);
///
/// // The boxed service can still be cloned.
/// service.clone();
/// # fn assert_service<S, R>(svc: S) -> S
/// # where S: Service<R> { svc }
/// ```
///
/// [`BoxCloneSyncServiceLayer`]: crate::util::BoxCloneSyncServiceLayer
/// [`BoxCloneSyncService`]: crate::util::BoxCloneSyncService
/// [`boxed_clone`]: Self::boxed_clone
#[cfg(feature = "util")]
pub fn boxed_clone_sync<S, R>(
self,
) -> ServiceBuilder<
Stack<
crate::util::BoxCloneSyncServiceLayer<
S,
R,
<L::Service as Service<R>>::Response,
<L::Service as Service<R>>::Error,
>,
Identity,
>,
>
where
L: Layer<S> + Send + Sync + 'static,
L::Service: Service<R> + Clone + Send + Sync + 'static,
<L::Service as Service<R>>::Response: Send + Sync + 'static,
<L::Service as Service<R>>::Error: Send + Sync + 'static,
<L::Service as Service<R>>::Future: Send + Sync + 'static,
{
let layer = self.into_inner();

ServiceBuilder::new().layer(crate::util::BoxCloneSyncServiceLayer::new(layer))
}
}

impl<L: fmt::Debug> fmt::Debug for ServiceBuilder<L> {
Expand Down

0 comments on commit 68c3b7e

Please sign in to comment.