builder: Add ServiceBuilder::layer_fn (#560)

This gem as just [sitting in Tonic][sit] waiting to be upstreamed.

[sit]: https://github.com/hyperium/tonic/blob/master/tonic/src/transport/service/layer.rs

Co-authored-by: Eliza Weisman <eliza@buoyant.io>
This commit is contained in:
David Pedersen
2021-02-25 22:33:35 +01:00
committed by GitHub
parent 05ff82abe8
commit df5774e76c
2 changed files with 10 additions and 0 deletions
+1
View File
@@ -6,6 +6,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
# Unreleased
- **builder**: Add `ServiceBuilder::layer_fn` to add a layer built from a function.
- **builder**: Add `ServiceBuilder::map_future` for transforming the futures produced
by a service.
- **util**: Add example for `service_fn`.
+9
View File
@@ -159,6 +159,15 @@ impl<L> ServiceBuilder<L> {
self.layer(crate::util::option_layer(layer))
}
/// Add a [`Layer`] built from a function that accepts a service and returns another service.
///
/// See the documentation for [`layer_fn`] for more details.
///
/// [`layer_fn`]: crate::layer::layer_fn
pub fn layer_fn<F>(self, f: F) -> ServiceBuilder<Stack<crate::layer::LayerFn<F>, L>> {
self.layer(crate::layer::layer_fn(f))
}
/// Buffer requests when when the next layer is not ready.
///
/// This wraps the inner service with an instance of the [`Buffer`]