diff --git a/tower/src/util/and_then.rs b/tower/src/util/and_then.rs index 0cc892af..53b67cd4 100644 --- a/tower/src/util/and_then.rs +++ b/tower/src/util/and_then.rs @@ -57,6 +57,15 @@ impl AndThen { pub fn new(inner: S, f: F) -> Self { AndThen { f, inner } } + + /// Returns a new [`Layer`] that produces [`AndThen`] services. + /// + /// This is a convenience function that simply calls [`AndThenLayer::new`]. + /// + /// [`Layer`]: tower_layer::Layer + pub fn layer(f: F) -> AndThenLayer { + AndThenLayer { f } + } } impl Service for AndThen diff --git a/tower/src/util/map_err.rs b/tower/src/util/map_err.rs index 3c888287..cbf018c6 100644 --- a/tower/src/util/map_err.rs +++ b/tower/src/util/map_err.rs @@ -12,7 +12,7 @@ pub struct MapErr { f: F, } -/// A [`Layer`] that produces a [`MapErr`] service. +/// A [`Layer`] that produces [`MapErr`] services. /// /// [`Layer`]: tower_layer::Layer #[derive(Debug)] @@ -32,6 +32,15 @@ impl MapErr { pub fn new(inner: S, f: F) -> Self { MapErr { f, inner } } + + /// Returns a new [`Layer`] that produces [`MapErr`] services. + /// + /// This is a convenience function that simply calls [`MapErrLayer::new`]. + /// + /// [`Layer`]: tower_layer::Layer + pub fn layer(f: F) -> MapErrLayer { + MapErrLayer { f } + } } impl Service for MapErr diff --git a/tower/src/util/map_request.rs b/tower/src/util/map_request.rs index 5c94ff0a..ceec179b 100644 --- a/tower/src/util/map_request.rs +++ b/tower/src/util/map_request.rs @@ -16,6 +16,15 @@ impl MapRequest { pub fn new(inner: S, f: F) -> Self { MapRequest { inner, f } } + + /// Returns a new [`Layer`] that produces [`MapRequest`] services. + /// + /// This is a convenience function that simply calls [`MapRequestLayer::new`]. + /// + /// [`Layer`]: tower_layer::Layer + pub fn layer(f: F) -> MapRequestLayer { + MapRequestLayer { f } + } } impl Service for MapRequest @@ -38,7 +47,7 @@ where } } -/// A [`Layer`] that produces a [`MapRequest`] service. +/// A [`Layer`] that produces [`MapRequest`] services. /// /// [`Layer`]: tower_layer::Layer #[derive(Debug)] diff --git a/tower/src/util/map_response.rs b/tower/src/util/map_response.rs index 9006c1a7..2bccdb13 100644 --- a/tower/src/util/map_response.rs +++ b/tower/src/util/map_response.rs @@ -32,6 +32,15 @@ impl MapResponse { pub fn new(inner: S, f: F) -> Self { MapResponse { f, inner } } + + /// Returns a new [`Layer`] that produces [`MapResponse`] services. + /// + /// This is a convenience function that simply calls [`MapResponseLayer::new`]. + /// + /// [`Layer`]: tower_layer::Layer + pub fn layer(f: F) -> MapResponseLayer { + MapResponseLayer { f } + } } impl Service for MapResponse diff --git a/tower/src/util/map_result.rs b/tower/src/util/map_result.rs index dfdd76c7..eb0af334 100644 --- a/tower/src/util/map_result.rs +++ b/tower/src/util/map_result.rs @@ -32,6 +32,15 @@ impl MapResult { pub fn new(inner: S, f: F) -> Self { MapResult { f, inner } } + + /// Returns a new [`Layer`] that produces [`MapResult`] services. + /// + /// This is a convenience function that simply calls [`MapResultLayer::new`]. + /// + /// [`Layer`]: tower_layer::Layer + pub fn layer(f: F) -> MapResultLayer { + MapResultLayer { f } + } } impl Service for MapResult diff --git a/tower/src/util/then.rs b/tower/src/util/then.rs index a187b5d9..63cd0896 100644 --- a/tower/src/util/then.rs +++ b/tower/src/util/then.rs @@ -28,6 +28,15 @@ impl Then { pub fn new(inner: S, f: F) -> Self { Then { f, inner } } + + /// Returns a new [`Layer`] that produces [`Then`] services. + /// + /// This is a convenience function that simply calls [`ThenLayer::new`]. + /// + /// [`Layer`]: tower_layer::Layer + pub fn layer(f: F) -> ThenLayer { + ThenLayer { f } + } } opaque_future! {