mirror of
https://github.com/openharmony/third_party_rust_tower.git
synced 2026-07-19 15:24:18 -04:00
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:
@@ -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`.
|
||||
|
||||
@@ -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`]
|
||||
|
||||
Reference in New Issue
Block a user