diff --git a/axum/CHANGELOG.md b/axum/CHANGELOG.md index be8f2af2..e865fa75 100644 --- a/axum/CHANGELOG.md +++ b/axum/CHANGELOG.md @@ -20,9 +20,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 `routing::{get, get_service, ..., MethodRouter}`. - **breaking:** `HandleErrorExt` has been removed in favor of `MethodRouter::handle_error`. +- **breaking:** The `Handler` trait is now defined as `Handler`. That is the type parameters have been swapped and `B` defaults to + `axum::body::Body` ([#527]) - Update WebSockets to use tokio-tungstenite 0.16 ([#525]) [#525]: https://github.com/tokio-rs/axum/pull/525 +[#527]: https://github.com/tokio-rs/axum/pull/527 # 0.3.3 (13. November, 2021) diff --git a/axum/src/handler/into_service.rs b/axum/src/handler/into_service.rs index 7b116bb6..613fd159 100644 --- a/axum/src/handler/into_service.rs +++ b/axum/src/handler/into_service.rs @@ -12,9 +12,9 @@ use tower_service::Service; /// An adapter that makes a [`Handler`] into a [`Service`]. /// /// Created with [`Handler::into_service`]. -pub struct IntoService { +pub struct IntoService { handler: H, - _marker: PhantomData (B, T)>, + _marker: PhantomData (T, B)>, } #[test] @@ -24,7 +24,7 @@ fn traits() { assert_sync::>(); } -impl IntoService { +impl IntoService { pub(super) fn new(handler: H) -> Self { Self { handler, @@ -33,7 +33,7 @@ impl IntoService { } } -impl fmt::Debug for IntoService { +impl fmt::Debug for IntoService { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { f.debug_tuple("IntoService") .field(&format_args!("...")) @@ -41,7 +41,7 @@ impl fmt::Debug for IntoService { } } -impl Clone for IntoService +impl Clone for IntoService where H: Clone, { @@ -53,9 +53,9 @@ where } } -impl Service> for IntoService +impl Service> for IntoService where - H: Handler + Clone + Send + 'static, + H: Handler + Clone + Send + 'static, B: Send + 'static, { type Response = Response; diff --git a/axum/src/handler/mod.rs b/axum/src/handler/mod.rs index 68e80045..6c3603a5 100644 --- a/axum/src/handler/mod.rs +++ b/axum/src/handler/mod.rs @@ -60,7 +60,7 @@ //! | //! ::: axum/src/handler/mod.rs:116:8 //! | -//! 116 | H: Handler, +//! 116 | H: Handler, //! | ------------- required by this bound in `axum::routing::get` //! ``` //! @@ -71,7 +71,7 @@ //! [axum-debug]: https://docs.rs/axum-debug use crate::{ - body::{box_body, BoxBody}, + body::{box_body, Body, BoxBody}, extract::{ connect_info::{Connected, IntoMakeServiceWithConnectInfo}, FromRequest, RequestParts, @@ -108,7 +108,7 @@ pub(crate) mod sealed { /// /// See the [module docs](crate::handler) for more details. #[async_trait] -pub trait Handler: Clone + Send + Sized + 'static { +pub trait Handler: Clone + Send + Sized + 'static { // This seals the trait. We cannot use the regular "sealed super trait" // approach due to coherence. #[doc(hidden)] @@ -155,7 +155,7 @@ pub trait Handler: Clone + Send + Sized + 'static { /// ``` fn layer(self, layer: L) -> Layered where - L: Layer>, + L: Layer>, { Layered::new(layer.layer(self.into_service())) } @@ -192,7 +192,7 @@ pub trait Handler: Clone + Send + Sized + 'static { /// ``` /// /// [`Router::fallback`]: crate::routing::Router::fallback - fn into_service(self) -> IntoService { + fn into_service(self) -> IntoService { IntoService::new(self) } @@ -219,7 +219,7 @@ pub trait Handler: Clone + Send + Sized + 'static { /// ``` /// /// [`MakeService`]: tower::make::MakeService - fn into_make_service(self) -> IntoMakeService> { + fn into_make_service(self) -> IntoMakeService> { IntoMakeService::new(self.into_service()) } @@ -253,7 +253,7 @@ pub trait Handler: Clone + Send + Sized + 'static { /// [`Router::into_make_service_with_connect_info`]: crate::routing::Router::into_make_service_with_connect_info fn into_make_service_with_connect_info( self, - ) -> IntoMakeServiceWithConnectInfo, C> + ) -> IntoMakeServiceWithConnectInfo, C> where C: Connected, { @@ -262,7 +262,7 @@ pub trait Handler: Clone + Send + Sized + 'static { } #[async_trait] -impl Handler for F +impl Handler<(), B> for F where F: FnOnce() -> Fut + Clone + Send + 'static, Fut: Future + Send, @@ -280,7 +280,7 @@ macro_rules! impl_handler { ( $($ty:ident),* $(,)? ) => { #[async_trait] #[allow(non_snake_case)] - impl Handler for F + impl Handler<($($ty,)*), B> for F where F: FnOnce($($ty,)*) -> Fut + Clone + Send + 'static, Fut: Future + Send, @@ -352,7 +352,7 @@ where } #[async_trait] -impl Handler for Layered +impl Handler for Layered where S: Service, Response = Response> + Clone + Send + 'static, S::Error: IntoResponse, diff --git a/axum/src/routing/method_routing.rs b/axum/src/routing/method_routing.rs index 271dfa45..1f76a799 100644 --- a/axum/src/routing/method_routing.rs +++ b/axum/src/routing/method_routing.rs @@ -134,9 +134,9 @@ macro_rules! top_level_handler_fn { $name:ident, $method:ident ) => { $(#[$m])+ - pub fn $name(handler: H) -> MethodRouter + pub fn $name(handler: H) -> MethodRouter where - H: Handler, + H: Handler, B: Send + 'static, T: 'static, { @@ -271,7 +271,7 @@ macro_rules! chained_handler_fn { $(#[$m])+ pub fn $name(self, handler: H) -> Self where - H: Handler, + H: Handler, T: 'static, { self.on(MethodFilter::$method, handler) @@ -417,9 +417,9 @@ top_level_handler_fn!(trace, TRACE); /// # axum::Server::bind(&"".parse().unwrap()).serve(app.into_make_service()).await.unwrap(); /// # }; /// ``` -pub fn on(filter: MethodFilter, handler: H) -> MethodRouter +pub fn on(filter: MethodFilter, handler: H) -> MethodRouter where - H: Handler, + H: Handler, B: Send + 'static, T: 'static, { @@ -463,9 +463,9 @@ where /// # axum::Server::bind(&"".parse().unwrap()).serve(app.into_make_service()).await.unwrap(); /// # }; /// ``` -pub fn any(handler: H) -> MethodRouter +pub fn any(handler: H) -> MethodRouter where - H: Handler, + H: Handler, B: Send + 'static, T: 'static, { @@ -557,7 +557,7 @@ where /// ``` pub fn on(self, filter: MethodFilter, handler: H) -> Self where - H: Handler, + H: Handler, T: 'static, { self.on_service_boxed_response_body(filter, handler.into_service())