Skip to content

Commit c4cb3b0

Browse files
authored
builder: Add ServiceBuilder::and_then (#601)
This one was missing. Was the only combinator from `ServiceExt` that wasn't on `ServiceBuilder` so now they match.
1 parent d91c0f5 commit c4cb3b0

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

tower/CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
88
# Unreleased
99

1010
- **builder**: Implement `Layer` for `ServiceBuilder`.
11+
- **builder**: Add `ServiceBuilder::and_then` analogous to
12+
`ServiceExt::and_then`
1113

1214
# 0.4.8 (May 28, 2021)
1315

tower/src/builder/mod.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -453,6 +453,28 @@ impl<L> ServiceBuilder<L> {
453453
self.layer(crate::util::ThenLayer::new(f))
454454
}
455455

456+
/// Executes a new future after this service's future resolves. This does
457+
/// not alter the behaviour of the [`poll_ready`] method.
458+
///
459+
/// This method can be used to change the [`Response`] type of the service
460+
/// into a different type. You can use this method to chain along a computation once the
461+
/// service's response has been resolved.
462+
///
463+
/// This wraps the inner service with an instance of the [`AndThen`]
464+
/// middleware.
465+
///
466+
/// See the documentation for the [`and_then` combinator] for details.
467+
///
468+
/// [`Response`]: crate::Service::Response
469+
/// [`poll_ready`]: crate::Service::poll_ready
470+
/// [`and_then` combinator]: crate::util::ServiceExt::and_then
471+
/// [`AndThen`]: crate::util::AndThen
472+
#[cfg(feature = "util")]
473+
#[cfg_attr(docsrs, doc(cfg(feature = "util")))]
474+
pub fn and_then<F>(self, f: F) -> ServiceBuilder<Stack<crate::util::AndThenLayer<F>, L>> {
475+
self.layer(crate::util::AndThenLayer::new(f))
476+
}
477+
456478
/// Maps this service's result type (`Result<Self::Response, Self::Error>`)
457479
/// to a different value, regardless of whether the future succeeds or
458480
/// fails.

0 commit comments

Comments
 (0)