Function tower::util::option_layer
source · [−]pub fn option_layer<L>(layer: Option<L>) -> Either<L, Identity>ⓘNotable traits for Either<A, B>impl<A, B, T, AE, BE> Future for Either<A, B>where
A: Future<Output = Result<T, AE>>,
AE: Into<BoxError>,
B: Future<Output = Result<T, BE>>,
BE: Into<BoxError>, type Output = Result<T, BoxError>;
Expand description
Convert an Option<Layer>
into a Layer
.
use tower::util::option_layer;
// Layer to apply a timeout if configured
let maybe_timeout = option_layer(timeout.map(TimeoutLayer::new));
ServiceBuilder::new()
.layer(maybe_timeout)
.service(svc);