From ca7ecb159bb1bc77c2c3623358ea028b0722e686 Mon Sep 17 00:00:00 2001 From: David Pedersen Date: Tue, 19 Apr 2022 16:16:54 +0200 Subject: [PATCH] Allow `Error: Into` for `Route::{layer, route_layer}` (#924) * Allow `Error: Into` for `Route::{layer, route_layer}` Fixes https://github.com/tokio-rs/axum/issues/922 * changelog --- axum/CHANGELOG.md | 2 ++ axum/src/routing/mod.rs | 15 +++++++-------- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/axum/CHANGELOG.md b/axum/CHANGELOG.md index 34ca6805..9c2027fc 100644 --- a/axum/CHANGELOG.md +++ b/axum/CHANGELOG.md @@ -10,9 +10,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - **added:** Add `AppendHeaders` for appending headers to a response rather than overriding them ([#927]) - **added:** Add `axum::extract::multipart::Field::chunk` method for streaming a single chunk from the field ([#901]) +- **changed:** Allow `Error: Into` for `Route::{layer, route_layer}` ([#924]) - **fixed:** Fix trailing slash redirection with query parameters ([#936]) [#901]: https://github.com/tokio-rs/axum/pull/901 +[#924]: https://github.com/tokio-rs/axum/pull/924 [#927]: https://github.com/tokio-rs/axum/pull/927 [#936]: https://github.com/tokio-rs/axum/pull/936 diff --git a/axum/src/routing/mod.rs b/axum/src/routing/mod.rs index 581e9241..df4352f3 100644 --- a/axum/src/routing/mod.rs +++ b/axum/src/routing/mod.rs @@ -291,15 +291,15 @@ where pub fn layer(self, layer: L) -> Router where L: Layer>, - L::Service: Service, Response = Response, Error = Infallible> - + Clone - + Send - + 'static, + L::Service: + Service, Response = Response> + Clone + Send + 'static, + >>::Error: Into + 'static, >>::Future: Send + 'static, NewResBody: HttpBody + Send + 'static, NewResBody::Error: Into, { let layer = ServiceBuilder::new() + .map_err(Into::into) .layer(MapResponseBodyLayer::new(boxed)) .layer(layer) .into_inner(); @@ -332,15 +332,14 @@ where pub fn route_layer(self, layer: L) -> Self where L: Layer>, - L::Service: Service, Response = Response, Error = Infallible> - + Clone - + Send - + 'static, + L::Service: Service, Response = Response> + Clone + Send + 'static, + >>::Error: Into + 'static, >>::Future: Send + 'static, NewResBody: HttpBody + Send + 'static, NewResBody::Error: Into, { let layer = ServiceBuilder::new() + .map_err(Into::into) .layer(MapResponseBodyLayer::new(boxed)) .layer(layer) .into_inner();