diff --git a/tower/CHANGELOG.md b/tower/CHANGELOG.md index 1e7497e9c..ca97e67e6 100644 --- a/tower/CHANGELOG.md +++ b/tower/CHANGELOG.md @@ -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`. diff --git a/tower/src/builder/mod.rs b/tower/src/builder/mod.rs index 20b1a36ce..f733861dd 100644 --- a/tower/src/builder/mod.rs +++ b/tower/src/builder/mod.rs @@ -159,6 +159,15 @@ impl ServiceBuilder { 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(self, f: F) -> ServiceBuilder, 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`]