Function layer_fn
fn layer_fn<T>(f: T) -> LayerFn<T>
Returns a new LayerFn that implements Layer by calling the
given function.
The Layer::layer method takes a type implementing Service and
returns a different type implementing Service. In many cases, this can
be implemented by a function or a closure. The LayerFn helper allows
writing simple Layer implementations without needing the boilerplate of
a new struct implementing Layer.
Example
# use Service;
# use ;
# use ;
# use fmt;
# use Infallible;
#
// A middleware that logs requests before forwarding them to another service
// A `Layer` that wraps services in `LogService`
let log_layer = layer_fn;
// An example service. This one uppercases strings
let uppercase_service = service_fn;
// Wrap our service in a `LogService` so requests are logged.
let wrapped_service = log_layer.layer;