diff --git a/axum-core/Cargo.toml b/axum-core/Cargo.toml index 8ed42530c0a..eb4540afb5e 100644 --- a/axum-core/Cargo.toml +++ b/axum-core/Cargo.toml @@ -18,7 +18,6 @@ tracing = ["dep:tracing"] __private_docs = ["dep:tower-http"] [dependencies] -async-trait = "0.1.67" bytes = "1.0" futures-util = { version = "0.3", default-features = false, features = ["alloc"] } http = "1.0.0" diff --git a/axum-core/src/ext_traits/mod.rs b/axum-core/src/ext_traits/mod.rs index 02595fbeac7..04d87f81511 100644 --- a/axum-core/src/ext_traits/mod.rs +++ b/axum-core/src/ext_traits/mod.rs @@ -6,13 +6,11 @@ mod tests { use std::convert::Infallible; use crate::extract::{FromRef, FromRequestParts}; - use async_trait::async_trait; use http::request::Parts; #[derive(Debug, Default, Clone, Copy)] pub(crate) struct State(pub(crate) S); - #[async_trait] impl FromRequestParts for State where InnerState: FromRef, @@ -32,7 +30,6 @@ mod tests { // some extractor that requires the state, such as `SignedCookieJar` pub(crate) struct RequiresState(pub(crate) String); - #[async_trait] impl FromRequestParts for RequiresState where S: Send + Sync, diff --git a/axum-core/src/ext_traits/request.rs b/axum-core/src/ext_traits/request.rs index 5b7aee783a0..1123fdd3d69 100644 --- a/axum-core/src/ext_traits/request.rs +++ b/axum-core/src/ext_traits/request.rs @@ -1,6 +1,6 @@ use crate::body::Body; use crate::extract::{DefaultBodyLimitKind, FromRequest, FromRequestParts, Request}; -use futures_util::future::BoxFuture; +use std::future::Future; mod sealed { pub trait Sealed {} @@ -20,7 +20,6 @@ pub trait RequestExt: sealed::Sealed + Sized { /// /// ``` /// use axum::{ - /// async_trait, /// extract::{Request, FromRequest}, /// body::Body, /// http::{header::CONTENT_TYPE, StatusCode}, @@ -30,7 +29,6 @@ pub trait RequestExt: sealed::Sealed + Sized { /// /// struct FormOrJson(T); /// - /// #[async_trait] /// impl FromRequest for FormOrJson /// where /// Json: FromRequest<()>, @@ -67,7 +65,7 @@ pub trait RequestExt: sealed::Sealed + Sized { /// } /// } /// ``` - fn extract(self) -> BoxFuture<'static, Result> + fn extract(self) -> impl Future> + Send where E: FromRequest<(), M> + 'static, M: 'static; @@ -83,7 +81,6 @@ pub trait RequestExt: sealed::Sealed + Sized { /// /// ``` /// use axum::{ - /// async_trait, /// body::Body, /// extract::{Request, FromRef, FromRequest}, /// RequestExt, @@ -93,7 +90,6 @@ pub trait RequestExt: sealed::Sealed + Sized { /// requires_state: RequiresState, /// } /// - /// #[async_trait] /// impl FromRequest for MyExtractor /// where /// String: FromRef, @@ -111,7 +107,6 @@ pub trait RequestExt: sealed::Sealed + Sized { /// // some extractor that consumes the request body and requires state /// struct RequiresState { /* ... */ } /// - /// #[async_trait] /// impl FromRequest for RequiresState /// where /// String: FromRef, @@ -124,7 +119,10 @@ pub trait RequestExt: sealed::Sealed + Sized { /// # } /// } /// ``` - fn extract_with_state(self, state: &S) -> BoxFuture<'_, Result> + fn extract_with_state( + self, + state: &S, + ) -> impl Future> + Send where E: FromRequest + 'static, S: Send + Sync; @@ -137,7 +135,6 @@ pub trait RequestExt: sealed::Sealed + Sized { /// /// ``` /// use axum::{ - /// async_trait, /// extract::{Path, Request, FromRequest}, /// response::{IntoResponse, Response}, /// body::Body, @@ -154,7 +151,6 @@ pub trait RequestExt: sealed::Sealed + Sized { /// payload: T, /// } /// - /// #[async_trait] /// impl FromRequest for MyExtractor /// where /// S: Send + Sync, @@ -179,7 +175,7 @@ pub trait RequestExt: sealed::Sealed + Sized { /// } /// } /// ``` - fn extract_parts(&mut self) -> BoxFuture<'_, Result> + fn extract_parts(&mut self) -> impl Future> + Send where E: FromRequestParts<()> + 'static; @@ -191,7 +187,6 @@ pub trait RequestExt: sealed::Sealed + Sized { /// /// ``` /// use axum::{ - /// async_trait, /// extract::{Request, FromRef, FromRequest, FromRequestParts}, /// http::request::Parts, /// response::{IntoResponse, Response}, @@ -204,7 +199,6 @@ pub trait RequestExt: sealed::Sealed + Sized { /// payload: T, /// } /// - /// #[async_trait] /// impl FromRequest for MyExtractor /// where /// String: FromRef, @@ -234,7 +228,6 @@ pub trait RequestExt: sealed::Sealed + Sized { /// /// struct RequiresState {} /// - /// #[async_trait] /// impl FromRequestParts for RequiresState /// where /// String: FromRef, @@ -250,7 +243,7 @@ pub trait RequestExt: sealed::Sealed + Sized { fn extract_parts_with_state<'a, E, S>( &'a mut self, state: &'a S, - ) -> BoxFuture<'a, Result> + ) -> impl Future> + Send + 'a where E: FromRequestParts + 'static, S: Send + Sync; @@ -267,7 +260,7 @@ pub trait RequestExt: sealed::Sealed + Sized { } impl RequestExt for Request { - fn extract(self) -> BoxFuture<'static, Result> + fn extract(self) -> impl Future> + Send where E: FromRequest<(), M> + 'static, M: 'static, @@ -275,7 +268,10 @@ impl RequestExt for Request { self.extract_with_state(&()) } - fn extract_with_state(self, state: &S) -> BoxFuture<'_, Result> + fn extract_with_state( + self, + state: &S, + ) -> impl Future> + Send where E: FromRequest + 'static, S: Send + Sync, @@ -283,17 +279,17 @@ impl RequestExt for Request { E::from_request(self, state) } - fn extract_parts(&mut self) -> BoxFuture<'_, Result> + fn extract_parts(&mut self) -> impl Future> + Send where E: FromRequestParts<()> + 'static, { self.extract_parts_with_state(&()) } - fn extract_parts_with_state<'a, E, S>( + async fn extract_parts_with_state<'a, E, S>( &'a mut self, state: &'a S, - ) -> BoxFuture<'a, Result> + ) -> Result where E: FromRequestParts + 'static, S: Send + Sync, @@ -306,17 +302,15 @@ impl RequestExt for Request { *req.extensions_mut() = std::mem::take(self.extensions_mut()); let (mut parts, ()) = req.into_parts(); - Box::pin(async move { - let result = E::from_request_parts(&mut parts, state).await; + let result = E::from_request_parts(&mut parts, state).await; - *self.version_mut() = parts.version; - *self.method_mut() = parts.method.clone(); - *self.uri_mut() = parts.uri.clone(); - *self.headers_mut() = std::mem::take(&mut parts.headers); - *self.extensions_mut() = std::mem::take(&mut parts.extensions); + *self.version_mut() = parts.version; + *self.method_mut() = parts.method.clone(); + *self.uri_mut() = parts.uri.clone(); + *self.headers_mut() = std::mem::take(&mut parts.headers); + *self.extensions_mut() = std::mem::take(&mut parts.extensions); - result - }) + result } fn with_limited_body(self) -> Request { @@ -345,7 +339,6 @@ mod tests { ext_traits::tests::{RequiresState, State}, extract::FromRef, }; - use async_trait::async_trait; use http::Method; #[tokio::test] @@ -414,7 +407,6 @@ mod tests { body: String, } - #[async_trait] impl FromRequest for WorksForCustomExtractor where S: Send + Sync, diff --git a/axum-core/src/ext_traits/request_parts.rs b/axum-core/src/ext_traits/request_parts.rs index e7063f4d8b9..9e1a3d1c16c 100644 --- a/axum-core/src/ext_traits/request_parts.rs +++ b/axum-core/src/ext_traits/request_parts.rs @@ -1,6 +1,6 @@ use crate::extract::FromRequestParts; -use futures_util::future::BoxFuture; use http::request::Parts; +use std::future::Future; mod sealed { pub trait Sealed {} @@ -21,7 +21,6 @@ pub trait RequestPartsExt: sealed::Sealed + Sized { /// response::{Response, IntoResponse}, /// http::request::Parts, /// RequestPartsExt, - /// async_trait, /// }; /// use std::collections::HashMap; /// @@ -30,7 +29,6 @@ pub trait RequestPartsExt: sealed::Sealed + Sized { /// query_params: HashMap, /// } /// - /// #[async_trait] /// impl FromRequestParts for MyExtractor /// where /// S: Send + Sync, @@ -54,7 +52,7 @@ pub trait RequestPartsExt: sealed::Sealed + Sized { /// } /// } /// ``` - fn extract(&mut self) -> BoxFuture<'_, Result> + fn extract(&mut self) -> impl Future> + Send where E: FromRequestParts<()> + 'static; @@ -70,14 +68,12 @@ pub trait RequestPartsExt: sealed::Sealed + Sized { /// response::{Response, IntoResponse}, /// http::request::Parts, /// RequestPartsExt, - /// async_trait, /// }; /// /// struct MyExtractor { /// requires_state: RequiresState, /// } /// - /// #[async_trait] /// impl FromRequestParts for MyExtractor /// where /// String: FromRef, @@ -97,7 +93,6 @@ pub trait RequestPartsExt: sealed::Sealed + Sized { /// struct RequiresState { /* ... */ } /// /// // some extractor that requires a `String` in the state - /// #[async_trait] /// impl FromRequestParts for RequiresState /// where /// String: FromRef, @@ -113,14 +108,14 @@ pub trait RequestPartsExt: sealed::Sealed + Sized { fn extract_with_state<'a, E, S>( &'a mut self, state: &'a S, - ) -> BoxFuture<'a, Result> + ) -> impl Future> + Send + 'a where E: FromRequestParts + 'static, S: Send + Sync; } impl RequestPartsExt for Parts { - fn extract(&mut self) -> BoxFuture<'_, Result> + fn extract(&mut self) -> impl Future> + Send where E: FromRequestParts<()> + 'static, { @@ -130,7 +125,7 @@ impl RequestPartsExt for Parts { fn extract_with_state<'a, E, S>( &'a mut self, state: &'a S, - ) -> BoxFuture<'a, Result> + ) -> impl Future> + Send + 'a where E: FromRequestParts + 'static, S: Send + Sync, @@ -148,7 +143,6 @@ mod tests { ext_traits::tests::{RequiresState, State}, extract::FromRef, }; - use async_trait::async_trait; use http::{Method, Request}; #[tokio::test] @@ -181,7 +175,6 @@ mod tests { from_state: String, } - #[async_trait] impl FromRequestParts for WorksForCustomExtractor where S: Send + Sync, diff --git a/axum-core/src/extract/mod.rs b/axum-core/src/extract/mod.rs index c8e2d2196f1..436400e117c 100644 --- a/axum-core/src/extract/mod.rs +++ b/axum-core/src/extract/mod.rs @@ -5,9 +5,9 @@ //! [`axum::extract`]: https://docs.rs/axum/0.7/axum/extract/index.html use crate::{body::Body, response::IntoResponse}; -use async_trait::async_trait; use http::request::Parts; use std::convert::Infallible; +use std::future::Future; pub mod rejection; @@ -42,7 +42,6 @@ mod private { /// See [`axum::extract`] for more general docs about extractors. /// /// [`axum::extract`]: https://docs.rs/axum/0.7/axum/extract/index.html -#[async_trait] #[cfg_attr( nightly_error_messages, diagnostic::on_unimplemented( @@ -55,7 +54,10 @@ pub trait FromRequestParts: Sized { type Rejection: IntoResponse; /// Perform the extraction. - async fn from_request_parts(parts: &mut Parts, state: &S) -> Result; + fn from_request_parts( + parts: &mut Parts, + state: &S, + ) -> impl Future> + Send; } /// Types that can be created from requests. @@ -69,7 +71,6 @@ pub trait FromRequestParts: Sized { /// See [`axum::extract`] for more general docs about extractors. /// /// [`axum::extract`]: https://docs.rs/axum/0.7/axum/extract/index.html -#[async_trait] #[cfg_attr( nightly_error_messages, diagnostic::on_unimplemented( @@ -82,10 +83,12 @@ pub trait FromRequest: Sized { type Rejection: IntoResponse; /// Perform the extraction. - async fn from_request(req: Request, state: &S) -> Result; + fn from_request( + req: Request, + state: &S, + ) -> impl Future> + Send; } -#[async_trait] impl FromRequest for T where S: Send + Sync, @@ -99,7 +102,6 @@ where } } -#[async_trait] impl FromRequestParts for Option where T: FromRequestParts, @@ -115,7 +117,6 @@ where } } -#[async_trait] impl FromRequest for Option where T: FromRequest, @@ -128,7 +129,6 @@ where } } -#[async_trait] impl FromRequestParts for Result where T: FromRequestParts, @@ -141,7 +141,6 @@ where } } -#[async_trait] impl FromRequest for Result where T: FromRequest, diff --git a/axum-core/src/extract/request_parts.rs b/axum-core/src/extract/request_parts.rs index 73f54db793f..4196a60c88f 100644 --- a/axum-core/src/extract/request_parts.rs +++ b/axum-core/src/extract/request_parts.rs @@ -1,12 +1,10 @@ use super::{rejection::*, FromRequest, FromRequestParts, Request}; use crate::{body::Body, RequestExt}; -use async_trait::async_trait; use bytes::Bytes; use http::{request::Parts, Extensions, HeaderMap, Method, Uri, Version}; use http_body_util::BodyExt; use std::convert::Infallible; -#[async_trait] impl FromRequest for Request where S: Send + Sync, @@ -18,7 +16,6 @@ where } } -#[async_trait] impl FromRequestParts for Method where S: Send + Sync, @@ -30,7 +27,6 @@ where } } -#[async_trait] impl FromRequestParts for Uri where S: Send + Sync, @@ -42,7 +38,6 @@ where } } -#[async_trait] impl FromRequestParts for Version where S: Send + Sync, @@ -59,7 +54,6 @@ where /// Prefer using [`TypedHeader`] to extract only the headers you need. /// /// [`TypedHeader`]: https://docs.rs/axum/0.7/axum/extract/struct.TypedHeader.html -#[async_trait] impl FromRequestParts for HeaderMap where S: Send + Sync, @@ -71,7 +65,6 @@ where } } -#[async_trait] impl FromRequest for Bytes where S: Send + Sync, @@ -90,7 +83,6 @@ where } } -#[async_trait] impl FromRequest for String where S: Send + Sync, @@ -114,7 +106,6 @@ where } } -#[async_trait] impl FromRequestParts for Parts where S: Send + Sync, @@ -126,7 +117,6 @@ where } } -#[async_trait] impl FromRequestParts for Extensions where S: Send + Sync, @@ -138,7 +128,6 @@ where } } -#[async_trait] impl FromRequest for Body where S: Send + Sync, diff --git a/axum-core/src/extract/tuple.rs b/axum-core/src/extract/tuple.rs index 021b9616df4..cbd91a7fb37 100644 --- a/axum-core/src/extract/tuple.rs +++ b/axum-core/src/extract/tuple.rs @@ -1,10 +1,8 @@ use super::{FromRequest, FromRequestParts, Request}; use crate::response::{IntoResponse, Response}; -use async_trait::async_trait; use http::request::Parts; use std::convert::Infallible; -#[async_trait] impl FromRequestParts for () where S: Send + Sync, @@ -20,7 +18,6 @@ macro_rules! impl_from_request { ( [$($ty:ident),*], $last:ident ) => { - #[async_trait] #[allow(non_snake_case, unused_mut, unused_variables)] impl FromRequestParts for ($($ty,)* $last,) where @@ -46,7 +43,6 @@ macro_rules! impl_from_request { // This impl must not be generic over M, otherwise it would conflict with the blanket // implementation of `FromRequest` for `T: FromRequestParts`. - #[async_trait] #[allow(non_snake_case, unused_mut, unused_variables)] impl FromRequest for ($($ty,)* $last,) where diff --git a/axum-extra/src/either.rs b/axum-extra/src/either.rs index 2742debb858..9fa1f82f3f1 100755 --- a/axum-extra/src/either.rs +++ b/axum-extra/src/either.rs @@ -7,7 +7,6 @@ //! use axum::{ //! body::Bytes, //! Router, -//! async_trait, //! routing::get, //! extract::FromRequestParts, //! }; @@ -15,7 +14,6 @@ //! // extractors for checking permissions //! struct AdminPermissions {} //! -//! #[async_trait] //! impl FromRequestParts for AdminPermissions //! where //! S: Send + Sync, @@ -29,7 +27,6 @@ //! //! struct User {} //! -//! #[async_trait] //! impl FromRequestParts for User //! where //! S: Send + Sync, @@ -96,7 +93,6 @@ use std::task::{Context, Poll}; use axum::{ - async_trait, extract::FromRequestParts, response::{IntoResponse, Response}, }; @@ -236,7 +232,6 @@ macro_rules! impl_traits_for_either { [$($ident:ident),* $(,)?], $last:ident $(,)? ) => { - #[async_trait] impl FromRequestParts for $either<$($ident),*, $last> where $($ident: FromRequestParts),*, @@ -247,12 +242,12 @@ macro_rules! impl_traits_for_either { async fn from_request_parts(parts: &mut Parts, state: &S) -> Result { $( - if let Ok(value) = FromRequestParts::from_request_parts(parts, state).await { + if let Ok(value) = <$ident as FromRequestParts>::from_request_parts(parts, state).await { return Ok(Self::$ident(value)); } )* - FromRequestParts::from_request_parts(parts, state).await.map(Self::$last) + <$last as FromRequestParts>::from_request_parts(parts, state).await.map(Self::$last) } } diff --git a/axum-extra/src/extract/cached.rs b/axum-extra/src/extract/cached.rs index 6f7d6227b77..5f05caee5c6 100644 --- a/axum-extra/src/extract/cached.rs +++ b/axum-extra/src/extract/cached.rs @@ -1,7 +1,4 @@ -use axum::{ - async_trait, - extract::{Extension, FromRequestParts}, -}; +use axum::extract::{Extension, FromRequestParts}; use http::request::Parts; /// Cache results of other extractors. @@ -19,7 +16,6 @@ use http::request::Parts; /// ```rust /// use axum_extra::extract::Cached; /// use axum::{ -/// async_trait, /// extract::FromRequestParts, /// response::{IntoResponse, Response}, /// http::{StatusCode, request::Parts}, @@ -28,7 +24,6 @@ use http::request::Parts; /// #[derive(Clone)] /// struct Session { /* ... */ } /// -/// #[async_trait] /// impl FromRequestParts for Session /// where /// S: Send + Sync, @@ -43,7 +38,6 @@ use http::request::Parts; /// /// struct CurrentUser { /* ... */ } /// -/// #[async_trait] /// impl FromRequestParts for CurrentUser /// where /// S: Send + Sync, @@ -86,7 +80,6 @@ pub struct Cached(pub T); #[derive(Clone)] struct CachedEntry(T); -#[async_trait] impl FromRequestParts for Cached where S: Send + Sync, @@ -126,7 +119,6 @@ mod tests { #[derive(Clone, Debug, PartialEq, Eq)] struct Extractor(Instant); - #[async_trait] impl FromRequestParts for Extractor where S: Send + Sync, diff --git a/axum-extra/src/extract/cookie/mod.rs b/axum-extra/src/extract/cookie/mod.rs index efd2dcdf863..50fa6031ac9 100644 --- a/axum-extra/src/extract/cookie/mod.rs +++ b/axum-extra/src/extract/cookie/mod.rs @@ -3,7 +3,6 @@ //! See [`CookieJar`], [`SignedCookieJar`], and [`PrivateCookieJar`] for more details. use axum::{ - async_trait, extract::FromRequestParts, response::{IntoResponse, IntoResponseParts, Response, ResponseParts}, }; @@ -90,7 +89,6 @@ pub struct CookieJar { jar: cookie::CookieJar, } -#[async_trait] impl FromRequestParts for CookieJar where S: Send + Sync, diff --git a/axum-extra/src/extract/cookie/private.rs b/axum-extra/src/extract/cookie/private.rs index 911b0ef2ec2..3a7d0beee67 100644 --- a/axum-extra/src/extract/cookie/private.rs +++ b/axum-extra/src/extract/cookie/private.rs @@ -1,6 +1,5 @@ use super::{cookies_from_request, set_cookies, Cookie, Key}; use axum::{ - async_trait, extract::{FromRef, FromRequestParts}, response::{IntoResponse, IntoResponseParts, Response, ResponseParts}, }; @@ -122,7 +121,6 @@ impl fmt::Debug for PrivateCookieJar { } } -#[async_trait] impl FromRequestParts for PrivateCookieJar where S: Send + Sync, diff --git a/axum-extra/src/extract/cookie/signed.rs b/axum-extra/src/extract/cookie/signed.rs index b65df79f95e..87ba5444b5d 100644 --- a/axum-extra/src/extract/cookie/signed.rs +++ b/axum-extra/src/extract/cookie/signed.rs @@ -1,6 +1,5 @@ use super::{cookies_from_request, set_cookies}; use axum::{ - async_trait, extract::{FromRef, FromRequestParts}, response::{IntoResponse, IntoResponseParts, Response, ResponseParts}, }; @@ -139,7 +138,6 @@ impl fmt::Debug for SignedCookieJar { } } -#[async_trait] impl FromRequestParts for SignedCookieJar where S: Send + Sync, diff --git a/axum-extra/src/extract/form.rs b/axum-extra/src/extract/form.rs index 8729fb5a885..896cbf3da3d 100644 --- a/axum-extra/src/extract/form.rs +++ b/axum-extra/src/extract/form.rs @@ -1,5 +1,4 @@ use axum::{ - async_trait, extract::{rejection::RawFormRejection, FromRequest, RawForm, Request}, response::{IntoResponse, Response}, Error, RequestExt, @@ -44,7 +43,6 @@ pub struct Form(pub T); axum_core::__impl_deref!(Form); -#[async_trait] impl FromRequest for Form where T: DeserializeOwned, diff --git a/axum-extra/src/extract/multipart.rs b/axum-extra/src/extract/multipart.rs index 86725cab235..3c874a83fa1 100644 --- a/axum-extra/src/extract/multipart.rs +++ b/axum-extra/src/extract/multipart.rs @@ -3,7 +3,6 @@ //! See [`Multipart`] for more details. use axum::{ - async_trait, body::{Body, Bytes}, extract::FromRequest, response::{IntoResponse, Response}, @@ -90,7 +89,6 @@ pub struct Multipart { inner: multer::Multipart<'static>, } -#[async_trait] impl FromRequest for Multipart where S: Send + Sync, diff --git a/axum-extra/src/extract/optional_path.rs b/axum-extra/src/extract/optional_path.rs index ca1634500e0..83b7be72030 100644 --- a/axum-extra/src/extract/optional_path.rs +++ b/axum-extra/src/extract/optional_path.rs @@ -1,5 +1,4 @@ use axum::{ - async_trait, extract::{path::ErrorKind, rejection::PathRejection, FromRequestParts, Path}, RequestPartsExt, }; @@ -35,7 +34,6 @@ use serde::de::DeserializeOwned; #[derive(Debug)] pub struct OptionalPath(pub Option); -#[async_trait] impl FromRequestParts for OptionalPath where T: DeserializeOwned + Send + 'static, diff --git a/axum-extra/src/extract/query.rs b/axum-extra/src/extract/query.rs index bdeaf78e8a3..e1b3a47e618 100644 --- a/axum-extra/src/extract/query.rs +++ b/axum-extra/src/extract/query.rs @@ -1,5 +1,4 @@ use axum::{ - async_trait, extract::FromRequestParts, response::{IntoResponse, Response}, Error, @@ -55,7 +54,6 @@ use std::fmt; #[derive(Debug, Clone, Copy, Default)] pub struct Query(pub T); -#[async_trait] impl FromRequestParts for Query where T: DeserializeOwned, @@ -155,7 +153,6 @@ impl std::error::Error for QueryRejection { #[derive(Debug, Clone, Copy, Default)] pub struct OptionalQuery(pub Option); -#[async_trait] impl FromRequestParts for OptionalQuery where T: DeserializeOwned, diff --git a/axum-extra/src/extract/with_rejection.rs b/axum-extra/src/extract/with_rejection.rs index 1227a1ab13d..7555461e843 100644 --- a/axum-extra/src/extract/with_rejection.rs +++ b/axum-extra/src/extract/with_rejection.rs @@ -1,4 +1,3 @@ -use axum::async_trait; use axum::extract::{FromRequest, FromRequestParts, Request}; use axum::response::IntoResponse; use http::request::Parts; @@ -107,7 +106,6 @@ impl DerefMut for WithRejection { } } -#[async_trait] impl FromRequest for WithRejection where S: Send + Sync, @@ -122,7 +120,6 @@ where } } -#[async_trait] impl FromRequestParts for WithRejection where S: Send + Sync, @@ -152,7 +149,6 @@ mod tests { struct TestExtractor; struct TestRejection; - #[async_trait] impl FromRequestParts for TestExtractor where S: Send + Sync, diff --git a/axum-extra/src/handler/mod.rs b/axum-extra/src/handler/mod.rs index 4017e149a6d..915852a1feb 100644 --- a/axum-extra/src/handler/mod.rs +++ b/axum-extra/src/handler/mod.rs @@ -47,7 +47,6 @@ pub trait HandlerCallWithExtractors: Sized { /// use axum_extra::handler::HandlerCallWithExtractors; /// use axum::{ /// Router, - /// async_trait, /// routing::get, /// extract::FromRequestParts, /// }; @@ -68,7 +67,6 @@ pub trait HandlerCallWithExtractors: Sized { /// // extractors for checking permissions /// struct AdminPermissions {} /// - /// #[async_trait] /// impl FromRequestParts for AdminPermissions /// where /// S: Send + Sync, @@ -82,7 +80,6 @@ pub trait HandlerCallWithExtractors: Sized { /// /// struct User {} /// - /// #[async_trait] /// impl FromRequestParts for User /// where /// S: Send + Sync, diff --git a/axum-extra/src/json_lines.rs b/axum-extra/src/json_lines.rs index d72c23b6c62..8f8d34d5544 100644 --- a/axum-extra/src/json_lines.rs +++ b/axum-extra/src/json_lines.rs @@ -1,7 +1,6 @@ //! Newline delimited JSON extractor and response. use axum::{ - async_trait, body::Body, extract::{FromRequest, Request}, response::{IntoResponse, Response}, @@ -99,7 +98,6 @@ impl JsonLines { } } -#[async_trait] impl FromRequest for JsonLines where T: DeserializeOwned, diff --git a/axum-extra/src/protobuf.rs b/axum-extra/src/protobuf.rs index e3c4b51df56..2a308731284 100644 --- a/axum-extra/src/protobuf.rs +++ b/axum-extra/src/protobuf.rs @@ -1,7 +1,6 @@ //! Protocol Buffer extractor and response. use axum::{ - async_trait, extract::{rejection::BytesRejection, FromRequest, Request}, response::{IntoResponse, Response}, }; @@ -90,7 +89,6 @@ use prost::Message; #[must_use] pub struct Protobuf(pub T); -#[async_trait] impl FromRequest for Protobuf where T: Message + Default, diff --git a/axum-extra/src/typed_header.rs b/axum-extra/src/typed_header.rs index aa89e81ddfc..d10c3a3217a 100644 --- a/axum-extra/src/typed_header.rs +++ b/axum-extra/src/typed_header.rs @@ -1,7 +1,6 @@ //! Extractor and response for typed headers. use axum::{ - async_trait, extract::FromRequestParts, response::{IntoResponse, IntoResponseParts, Response, ResponseParts}, }; @@ -55,7 +54,6 @@ use std::convert::Infallible; #[must_use] pub struct TypedHeader(pub T); -#[async_trait] impl FromRequestParts for TypedHeader where T: Header, diff --git a/axum-macros/src/from_request.rs b/axum-macros/src/from_request.rs index 474dd0cd653..1e3958b5a7b 100644 --- a/axum-macros/src/from_request.rs +++ b/axum-macros/src/from_request.rs @@ -373,7 +373,6 @@ fn impl_struct_by_extracting_each_field( Ok(match tr { Trait::FromRequest => quote! { - #[::axum::async_trait] #[automatically_derived] impl<#impl_generics> ::axum::extract::FromRequest<#trait_generics> for #ident where @@ -390,7 +389,6 @@ fn impl_struct_by_extracting_each_field( } }, Trait::FromRequestParts => quote! { - #[::axum::async_trait] #[automatically_derived] impl<#impl_generics> ::axum::extract::FromRequestParts<#trait_generics> for #ident where @@ -807,7 +805,6 @@ fn impl_struct_by_extracting_all_at_once( let tokens = match tr { Trait::FromRequest => { quote_spanned! {path_span=> - #[::axum::async_trait] #[automatically_derived] impl<#impl_generics> ::axum::extract::FromRequest<#trait_generics> for #ident #ident_generics where @@ -831,7 +828,6 @@ fn impl_struct_by_extracting_all_at_once( } Trait::FromRequestParts => { quote_spanned! {path_span=> - #[::axum::async_trait] #[automatically_derived] impl<#impl_generics> ::axum::extract::FromRequestParts<#trait_generics> for #ident #ident_generics where @@ -920,7 +916,6 @@ fn impl_enum_by_extracting_all_at_once( let tokens = match tr { Trait::FromRequest => { quote_spanned! {path_span=> - #[::axum::async_trait] #[automatically_derived] impl<#impl_generics> ::axum::extract::FromRequest<#trait_generics> for #ident where @@ -942,7 +937,6 @@ fn impl_enum_by_extracting_all_at_once( } Trait::FromRequestParts => { quote_spanned! {path_span=> - #[::axum::async_trait] #[automatically_derived] impl<#impl_generics> ::axum::extract::FromRequestParts<#trait_generics> for #ident where diff --git a/axum-macros/src/typed_path.rs b/axum-macros/src/typed_path.rs index 61db3eb9ae1..61e1695b00e 100644 --- a/axum-macros/src/typed_path.rs +++ b/axum-macros/src/typed_path.rs @@ -133,7 +133,6 @@ fn expand_named_fields( let map_err_rejection = map_err_rejection(&rejection); let from_request_impl = quote! { - #[::axum::async_trait] #[automatically_derived] impl ::axum::extract::FromRequestParts for #ident where @@ -238,7 +237,6 @@ fn expand_unnamed_fields( let map_err_rejection = map_err_rejection(&rejection); let from_request_impl = quote! { - #[::axum::async_trait] #[automatically_derived] impl ::axum::extract::FromRequestParts for #ident where @@ -322,7 +320,6 @@ fn expand_unit_fields( }; let from_request_impl = quote! { - #[::axum::async_trait] #[automatically_derived] impl ::axum::extract::FromRequestParts for #ident where diff --git a/axum-macros/tests/debug_handler/fail/extract_self_mut.rs b/axum-macros/tests/debug_handler/fail/extract_self_mut.rs index 21ae99d6b8d..eb17c1df522 100644 --- a/axum-macros/tests/debug_handler/fail/extract_self_mut.rs +++ b/axum-macros/tests/debug_handler/fail/extract_self_mut.rs @@ -1,12 +1,8 @@ -use axum::{ - async_trait, - extract::{Request, FromRequest}, -}; +use axum::extract::{FromRequest, Request}; use axum_macros::debug_handler; struct A; -#[async_trait] impl FromRequest for A where S: Send + Sync, diff --git a/axum-macros/tests/debug_handler/fail/extract_self_ref.rs b/axum-macros/tests/debug_handler/fail/extract_self_ref.rs index 8e32811994a..d70c5f23180 100644 --- a/axum-macros/tests/debug_handler/fail/extract_self_ref.rs +++ b/axum-macros/tests/debug_handler/fail/extract_self_ref.rs @@ -1,12 +1,8 @@ -use axum::{ - async_trait, - extract::{Request, FromRequest}, -}; +use axum::extract::{FromRequest, Request}; use axum_macros::debug_handler; struct A; -#[async_trait] impl FromRequest for A where S: Send + Sync, diff --git a/axum-macros/tests/debug_handler/pass/result_impl_into_response.rs b/axum-macros/tests/debug_handler/pass/result_impl_into_response.rs index 782fc9301c5..f23c9b627c8 100644 --- a/axum-macros/tests/debug_handler/pass/result_impl_into_response.rs +++ b/axum-macros/tests/debug_handler/pass/result_impl_into_response.rs @@ -1,4 +1,4 @@ -use axum::{async_trait, extract::FromRequestParts, http::request::Parts, response::IntoResponse}; +use axum::{extract::FromRequestParts, http::request::Parts, response::IntoResponse}; use axum_macros::debug_handler; fn main() {} @@ -115,7 +115,6 @@ impl A { } } -#[async_trait] impl FromRequestParts for A where S: Send + Sync, diff --git a/axum-macros/tests/debug_handler/pass/self_receiver.rs b/axum-macros/tests/debug_handler/pass/self_receiver.rs index 9b722845025..3fbcc4e03b7 100644 --- a/axum-macros/tests/debug_handler/pass/self_receiver.rs +++ b/axum-macros/tests/debug_handler/pass/self_receiver.rs @@ -1,12 +1,8 @@ -use axum::{ - async_trait, - extract::{Request, FromRequest}, -}; +use axum::extract::{FromRequest, Request}; use axum_macros::debug_handler; struct A; -#[async_trait] impl FromRequest for A where S: Send + Sync, @@ -18,7 +14,6 @@ where } } -#[async_trait] impl FromRequest for Box where S: Send + Sync, diff --git a/axum-macros/tests/debug_handler/pass/set_state.rs b/axum-macros/tests/debug_handler/pass/set_state.rs index 60a7a3304ea..72bba5aede3 100644 --- a/axum-macros/tests/debug_handler/pass/set_state.rs +++ b/axum-macros/tests/debug_handler/pass/set_state.rs @@ -1,6 +1,5 @@ +use axum::extract::{FromRef, FromRequest, Request}; use axum_macros::debug_handler; -use axum::extract::{Request, FromRef, FromRequest}; -use axum::async_trait; #[debug_handler(state = AppState)] async fn handler(_: A) {} @@ -10,7 +9,6 @@ struct AppState; struct A; -#[async_trait] impl FromRequest for A where S: Send + Sync, diff --git a/axum-macros/tests/from_request/pass/override_rejection.rs b/axum-macros/tests/from_request/pass/override_rejection.rs index 779058b9fca..736006edad2 100644 --- a/axum-macros/tests/from_request/pass/override_rejection.rs +++ b/axum-macros/tests/from_request/pass/override_rejection.rs @@ -1,10 +1,9 @@ use axum::{ - async_trait, - extract::{Request, rejection::ExtensionRejection, FromRequest}, + body::Body, + extract::{rejection::ExtensionRejection, FromRequest, Request}, http::StatusCode, response::{IntoResponse, Response}, routing::get, - body::Body, Extension, Router, }; @@ -27,7 +26,6 @@ struct MyExtractor { struct OtherExtractor; -#[async_trait] impl FromRequest for OtherExtractor where S: Send + Sync, diff --git a/axum-macros/tests/from_request/pass/override_rejection_parts.rs b/axum-macros/tests/from_request/pass/override_rejection_parts.rs index 8ef9cb22dbb..7cc27de24c5 100644 --- a/axum-macros/tests/from_request/pass/override_rejection_parts.rs +++ b/axum-macros/tests/from_request/pass/override_rejection_parts.rs @@ -1,5 +1,4 @@ use axum::{ - async_trait, extract::{rejection::ExtensionRejection, FromRequestParts}, http::{request::Parts, StatusCode}, response::{IntoResponse, Response}, @@ -26,7 +25,6 @@ struct MyExtractor { struct OtherExtractor; -#[async_trait] impl FromRequestParts for OtherExtractor where S: Send + Sync, diff --git a/axum/CHANGELOG.md b/axum/CHANGELOG.md index 679fdddd366..5225370aa03 100644 --- a/axum/CHANGELOG.md +++ b/axum/CHANGELOG.md @@ -561,7 +561,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ```rust struct MyExtractor { /* ... */ } - #[async_trait] impl FromRequest for MyExtractor where B: Send, @@ -580,13 +579,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 use axum::{ extract::{FromRequest, FromRequestParts}, http::{StatusCode, Request, request::Parts}, - async_trait, }; struct MyExtractor { /* ... */ } // implement `FromRequestParts` if you don't need to consume the request body - #[async_trait] impl FromRequestParts for MyExtractor where S: Send + Sync, @@ -599,7 +596,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 } // implement `FromRequest` if you do need to consume the request body - #[async_trait] impl FromRequest for MyExtractor where S: Send + Sync, @@ -1147,7 +1143,6 @@ Yanked, as it didn't compile in release mode. ```rust struct MyExtractor { /* ... */ } - #[async_trait] impl FromRequest for MyExtractor where B: Send, @@ -1166,13 +1161,11 @@ Yanked, as it didn't compile in release mode. use axum::{ extract::{FromRequest, FromRequestParts}, http::{StatusCode, Request, request::Parts}, - async_trait, }; struct MyExtractor { /* ... */ } // implement `FromRequestParts` if you don't need to consume the request body - #[async_trait] impl FromRequestParts for MyExtractor where S: Send + Sync, @@ -1185,7 +1178,6 @@ Yanked, as it didn't compile in release mode. } // implement `FromRequest` if you do need to consume the request body - #[async_trait] impl FromRequest for MyExtractor where S: Send + Sync, diff --git a/axum/Cargo.toml b/axum/Cargo.toml index f8e1aac9b0c..0bbe588b295 100644 --- a/axum/Cargo.toml +++ b/axum/Cargo.toml @@ -31,7 +31,6 @@ ws = ["dep:hyper", "tokio", "dep:tokio-tungstenite", "dep:sha1", "dep:base64"] __private_docs = ["tower/full", "dep:tower-http"] [dependencies] -async-trait = "0.1.67" axum-core = { path = "../axum-core", version = "0.4.1" } bytes = "1.0" futures-util = { version = "0.3", default-features = false, features = ["alloc"] } @@ -191,7 +190,6 @@ allowed = [ "tower_service", # >=1.0 - "async_trait", "bytes", "http", "http_body", diff --git a/axum/src/docs/extract.md b/axum/src/docs/extract.md index 384b233dbfa..d3f2ecaa57e 100644 --- a/axum/src/docs/extract.md +++ b/axum/src/docs/extract.md @@ -421,7 +421,6 @@ request body: ```rust,no_run use axum::{ - async_trait, extract::FromRequestParts, routing::get, Router, @@ -434,7 +433,6 @@ use axum::{ struct ExtractUserAgent(HeaderValue); -#[async_trait] impl FromRequestParts for ExtractUserAgent where S: Send + Sync, @@ -464,7 +462,6 @@ If your extractor needs to consume the request body you must implement [`FromReq ```rust,no_run use axum::{ - async_trait, extract::{Request, FromRequest}, response::{Response, IntoResponse}, body::{Bytes, Body}, @@ -478,7 +475,6 @@ use axum::{ struct ValidatedBody(Bytes); -#[async_trait] impl FromRequest for ValidatedBody where Bytes: FromRequest, @@ -518,7 +514,6 @@ use axum::{ extract::{FromRequest, Request, FromRequestParts}, http::request::Parts, body::Body, - async_trait, }; use std::convert::Infallible; @@ -526,7 +521,6 @@ use std::convert::Infallible; struct MyExtractor; // `MyExtractor` implements both `FromRequest` -#[async_trait] impl FromRequest for MyExtractor where S: Send + Sync, @@ -540,7 +534,6 @@ where } // and `FromRequestParts` -#[async_trait] impl FromRequestParts for MyExtractor where S: Send + Sync, @@ -574,7 +567,6 @@ in your implementation. ```rust use axum::{ - async_trait, extract::{Extension, FromRequestParts}, http::{StatusCode, HeaderMap, request::Parts}, response::{IntoResponse, Response}, @@ -591,7 +583,6 @@ struct AuthenticatedUser { // ... } -#[async_trait] impl FromRequestParts for AuthenticatedUser where S: Send + Sync, @@ -645,7 +636,6 @@ use axum::{ routing::get, extract::{Request, FromRequest, FromRequestParts}, http::{HeaderMap, request::Parts}, - async_trait, }; use std::time::{Instant, Duration}; @@ -656,7 +646,6 @@ struct Timing { } // we must implement both `FromRequestParts` -#[async_trait] impl FromRequestParts for Timing where S: Send + Sync, @@ -676,7 +665,6 @@ where } // and `FromRequest` -#[async_trait] impl FromRequest for Timing where S: Send + Sync, diff --git a/axum/src/extension.rs b/axum/src/extension.rs index a72568ac6c4..59ca93c84a7 100644 --- a/axum/src/extension.rs +++ b/axum/src/extension.rs @@ -1,5 +1,4 @@ use crate::{extract::rejection::*, response::IntoResponseParts}; -use async_trait::async_trait; use axum_core::{ extract::FromRequestParts, response::{IntoResponse, Response, ResponseParts}, @@ -70,7 +69,6 @@ use tower_service::Service; #[must_use] pub struct Extension(pub T); -#[async_trait] impl FromRequestParts for Extension where T: Clone + Send + Sync + 'static, diff --git a/axum/src/extract/connect_info.rs b/axum/src/extract/connect_info.rs index 3036d375bed..3252af1c673 100644 --- a/axum/src/extract/connect_info.rs +++ b/axum/src/extract/connect_info.rs @@ -7,7 +7,6 @@ use crate::extension::AddExtension; use super::{Extension, FromRequestParts}; -use async_trait::async_trait; use http::request::Parts; use std::{ convert::Infallible, @@ -139,7 +138,6 @@ opaque_future! { #[derive(Clone, Copy, Debug)] pub struct ConnectInfo(pub T); -#[async_trait] impl FromRequestParts for ConnectInfo where S: Send + Sync, diff --git a/axum/src/extract/host.rs b/axum/src/extract/host.rs index d5be6a978da..5ffb792963a 100644 --- a/axum/src/extract/host.rs +++ b/axum/src/extract/host.rs @@ -2,7 +2,6 @@ use super::{ rejection::{FailedToResolveHost, HostRejection}, FromRequestParts, }; -use async_trait::async_trait; use http::{ header::{HeaderMap, FORWARDED}, request::Parts, @@ -23,7 +22,6 @@ const X_FORWARDED_HOST_HEADER_KEY: &str = "X-Forwarded-Host"; #[derive(Debug, Clone)] pub struct Host(pub String); -#[async_trait] impl FromRequestParts for Host where S: Send + Sync, diff --git a/axum/src/extract/matched_path.rs b/axum/src/extract/matched_path.rs index cdb49b4db36..7cd819d54b7 100644 --- a/axum/src/extract/matched_path.rs +++ b/axum/src/extract/matched_path.rs @@ -1,6 +1,5 @@ use super::{rejection::*, FromRequestParts}; use crate::routing::{RouteId, NEST_TAIL_PARAM_CAPTURE}; -use async_trait::async_trait; use http::request::Parts; use std::{collections::HashMap, sync::Arc}; @@ -63,7 +62,6 @@ impl MatchedPath { } } -#[async_trait] impl FromRequestParts for MatchedPath where S: Send + Sync, diff --git a/axum/src/extract/multipart.rs b/axum/src/extract/multipart.rs index 5c7ae7267c4..04864c7e648 100644 --- a/axum/src/extract/multipart.rs +++ b/axum/src/extract/multipart.rs @@ -4,7 +4,6 @@ use super::{FromRequest, Request}; use crate::body::Bytes; -use async_trait::async_trait; use axum_core::{ __composite_rejection as composite_rejection, __define_rejection as define_rejection, response::{IntoResponse, Response}, @@ -65,7 +64,6 @@ pub struct Multipart { inner: multer::Multipart<'static>, } -#[async_trait] impl FromRequest for Multipart where S: Send + Sync, diff --git a/axum/src/extract/nested_path.rs b/axum/src/extract/nested_path.rs index f31fe3faba4..9477f15af02 100644 --- a/axum/src/extract/nested_path.rs +++ b/axum/src/extract/nested_path.rs @@ -4,7 +4,6 @@ use std::{ }; use crate::extract::Request; -use async_trait::async_trait; use axum_core::extract::FromRequestParts; use http::request::Parts; use tower_layer::{layer_fn, Layer}; @@ -47,7 +46,6 @@ impl NestedPath { } } -#[async_trait] impl FromRequestParts for NestedPath where S: Send + Sync, diff --git a/axum/src/extract/path/mod.rs b/axum/src/extract/path/mod.rs index 0be9008803b..e8bcb0a922e 100644 --- a/axum/src/extract/path/mod.rs +++ b/axum/src/extract/path/mod.rs @@ -8,7 +8,6 @@ use crate::{ routing::url_params::UrlParams, util::PercentDecodedStr, }; -use async_trait::async_trait; use axum_core::response::{IntoResponse, Response}; use http::{request::Parts, StatusCode}; use serde::de::DeserializeOwned; @@ -145,7 +144,6 @@ pub struct Path(pub T); axum_core::__impl_deref!(Path); -#[async_trait] impl FromRequestParts for Path where T: DeserializeOwned + Send, @@ -445,7 +443,6 @@ impl std::error::Error for FailedToDeserializePathParams {} #[derive(Debug)] pub struct RawPathParams(Vec<(Arc, PercentDecodedStr)>); -#[async_trait] impl FromRequestParts for RawPathParams where S: Send + Sync, diff --git a/axum/src/extract/query.rs b/axum/src/extract/query.rs index 37a40771c2c..fb14b334fb7 100644 --- a/axum/src/extract/query.rs +++ b/axum/src/extract/query.rs @@ -1,5 +1,4 @@ use super::{rejection::*, FromRequestParts}; -use async_trait::async_trait; use http::{request::Parts, Uri}; use serde::de::DeserializeOwned; @@ -46,7 +45,6 @@ use serde::de::DeserializeOwned; #[derive(Debug, Clone, Copy, Default)] pub struct Query(pub T); -#[async_trait] impl FromRequestParts for Query where T: DeserializeOwned, diff --git a/axum/src/extract/raw_form.rs b/axum/src/extract/raw_form.rs index f9c7d3572c2..de58c9e8a9b 100644 --- a/axum/src/extract/raw_form.rs +++ b/axum/src/extract/raw_form.rs @@ -1,4 +1,3 @@ -use async_trait::async_trait; use axum_core::extract::{FromRequest, Request}; use bytes::{Bytes, BytesMut}; use http::Method; @@ -30,7 +29,6 @@ use super::{ #[derive(Debug)] pub struct RawForm(pub Bytes); -#[async_trait] impl FromRequest for RawForm where S: Send + Sync, diff --git a/axum/src/extract/raw_query.rs b/axum/src/extract/raw_query.rs index d8c56f84a49..c792960a1b5 100644 --- a/axum/src/extract/raw_query.rs +++ b/axum/src/extract/raw_query.rs @@ -1,5 +1,4 @@ use super::FromRequestParts; -use async_trait::async_trait; use http::request::Parts; use std::convert::Infallible; @@ -25,7 +24,6 @@ use std::convert::Infallible; #[derive(Debug)] pub struct RawQuery(pub Option); -#[async_trait] impl FromRequestParts for RawQuery where S: Send + Sync, diff --git a/axum/src/extract/request_parts.rs b/axum/src/extract/request_parts.rs index 9756665b6c8..a05093dae87 100644 --- a/axum/src/extract/request_parts.rs +++ b/axum/src/extract/request_parts.rs @@ -1,5 +1,4 @@ use super::{Extension, FromRequestParts}; -use async_trait::async_trait; use http::{request::Parts, Uri}; use std::convert::Infallible; @@ -70,7 +69,6 @@ use std::convert::Infallible; pub struct OriginalUri(pub Uri); #[cfg(feature = "original-uri")] -#[async_trait] impl FromRequestParts for OriginalUri where S: Send + Sync, diff --git a/axum/src/extract/state.rs b/axum/src/extract/state.rs index 1592a813df5..9ec916211cc 100644 --- a/axum/src/extract/state.rs +++ b/axum/src/extract/state.rs @@ -1,4 +1,3 @@ -use async_trait::async_trait; use axum_core::extract::{FromRef, FromRequestParts}; use http::request::Parts; use std::{ @@ -219,13 +218,11 @@ use std::{ /// ```rust /// use axum_core::extract::{FromRequestParts, FromRef}; /// use http::request::Parts; -/// use async_trait::async_trait; /// use std::convert::Infallible; /// /// // the extractor your library provides /// struct MyLibraryExtractor; /// -/// #[async_trait] /// impl FromRequestParts for MyLibraryExtractor /// where /// // keep `S` generic but require that it can produce a `MyLibraryState` @@ -342,7 +339,6 @@ use std::{ #[derive(Debug, Default, Clone, Copy)] pub struct State(pub S); -#[async_trait] impl FromRequestParts for State where InnerState: FromRef, diff --git a/axum/src/extract/ws.rs b/axum/src/extract/ws.rs index 7781d6c2aa7..69850d0d00d 100644 --- a/axum/src/extract/ws.rs +++ b/axum/src/extract/ws.rs @@ -93,7 +93,6 @@ use self::rejection::*; use super::FromRequestParts; use crate::{body::Bytes, response::Response, Error}; -use async_trait::async_trait; use axum_core::body::Body; use futures_util::{ sink::{Sink, SinkExt}, @@ -381,7 +380,6 @@ impl OnFailedUpgrade for DefaultOnFailedUpgrade { fn call(self, _error: Error) {} } -#[async_trait] impl FromRequestParts for WebSocketUpgrade where S: Send + Sync, diff --git a/axum/src/form.rs b/axum/src/form.rs index 5f42b303228..79ae80e75c3 100644 --- a/axum/src/form.rs +++ b/axum/src/form.rs @@ -1,6 +1,5 @@ use crate::extract::Request; use crate::extract::{rejection::*, FromRequest, RawForm}; -use async_trait::async_trait; use axum_core::response::{IntoResponse, Response}; use axum_core::RequestExt; use http::header::CONTENT_TYPE; @@ -72,7 +71,6 @@ use serde::Serialize; #[must_use] pub struct Form(pub T); -#[async_trait] impl FromRequest for Form where T: DeserializeOwned, diff --git a/axum/src/json.rs b/axum/src/json.rs index ebff242dd42..4969a375405 100644 --- a/axum/src/json.rs +++ b/axum/src/json.rs @@ -1,6 +1,5 @@ use crate::extract::Request; use crate::extract::{rejection::*, FromRequest}; -use async_trait::async_trait; use axum_core::response::{IntoResponse, Response}; use bytes::{BufMut, Bytes, BytesMut}; use http::{ @@ -92,7 +91,6 @@ use serde::{de::DeserializeOwned, Serialize}; #[must_use] pub struct Json(pub T); -#[async_trait] impl FromRequest for Json where T: DeserializeOwned, diff --git a/axum/src/lib.rs b/axum/src/lib.rs index 42d5d41afc4..a30922b6cf8 100644 --- a/axum/src/lib.rs +++ b/axum/src/lib.rs @@ -443,8 +443,6 @@ pub mod serve; #[cfg(test)] mod test_helpers; -#[doc(no_inline)] -pub use async_trait::async_trait; #[doc(no_inline)] pub use http; diff --git a/axum/src/middleware/from_extractor.rs b/axum/src/middleware/from_extractor.rs index e120ffc1fce..b5983443eb2 100644 --- a/axum/src/middleware/from_extractor.rs +++ b/axum/src/middleware/from_extractor.rs @@ -39,12 +39,10 @@ use tower_service::Service; /// Router, /// http::{header, StatusCode, request::Parts}, /// }; -/// use async_trait::async_trait; /// /// // An extractor that performs authorization. /// struct RequireAuth; /// -/// #[async_trait] /// impl FromRequestParts for RequireAuth /// where /// S: Send + Sync, @@ -303,7 +301,7 @@ where #[cfg(test)] mod tests { use super::*; - use crate::{async_trait, handler::Handler, routing::get, test_helpers::*, Router}; + use crate::{handler::Handler, routing::get, test_helpers::*, Router}; use axum_core::extract::FromRef; use http::{header, request::Parts, StatusCode}; use tower_http::limit::RequestBodyLimitLayer; @@ -315,7 +313,6 @@ mod tests { struct RequireAuth; - #[async_trait::async_trait] impl FromRequestParts for RequireAuth where S: Send + Sync, @@ -368,7 +365,6 @@ mod tests { fn works_with_request_body_limit() { struct MyExtractor; - #[async_trait] impl FromRequestParts for MyExtractor where S: Send + Sync, diff --git a/examples/consume-body-in-extractor-or-middleware/src/main.rs b/examples/consume-body-in-extractor-or-middleware/src/main.rs index 107edb6f1b4..96ad49cd1cf 100644 --- a/examples/consume-body-in-extractor-or-middleware/src/main.rs +++ b/examples/consume-body-in-extractor-or-middleware/src/main.rs @@ -5,7 +5,6 @@ //! ``` use axum::{ - async_trait, body::{Body, Bytes}, extract::{FromRequest, Request}, http::StatusCode, @@ -74,7 +73,6 @@ async fn handler(BufferRequestBody(body): BufferRequestBody) { struct BufferRequestBody(Bytes); // we must implement `FromRequest` (and not `FromRequestParts`) to consume the body -#[async_trait] impl FromRequest for BufferRequestBody where S: Send + Sync, diff --git a/examples/customize-extractor-error/src/custom_extractor.rs b/examples/customize-extractor-error/src/custom_extractor.rs index 3611fba7965..4f75fb440de 100644 --- a/examples/customize-extractor-error/src/custom_extractor.rs +++ b/examples/customize-extractor-error/src/custom_extractor.rs @@ -5,7 +5,6 @@ //! - Boilerplate: Requires creating a new extractor for every custom rejection //! - Complexity: Manually implementing `FromRequest` results on more complex code use axum::{ - async_trait, extract::{rejection::JsonRejection, FromRequest, MatchedPath, Request}, http::StatusCode, response::IntoResponse, @@ -20,7 +19,6 @@ pub async fn handler(Json(value): Json) -> impl IntoResponse { // We define our own `Json` extractor that customizes the error from `axum::Json` pub struct Json(pub T); -#[async_trait] impl FromRequest for Json where axum::Json: FromRequest, diff --git a/examples/customize-path-rejection/src/main.rs b/examples/customize-path-rejection/src/main.rs index 4231eabf603..a8ba05d52cd 100644 --- a/examples/customize-path-rejection/src/main.rs +++ b/examples/customize-path-rejection/src/main.rs @@ -5,7 +5,6 @@ //! ``` use axum::{ - async_trait, extract::{path::ErrorKind, rejection::PathRejection, FromRequestParts}, http::{request::Parts, StatusCode}, response::IntoResponse, @@ -49,7 +48,6 @@ struct Params { // We define our own `Path` extractor that customizes the error from `axum::extract::Path` struct Path(T); -#[async_trait] impl FromRequestParts for Path where // these trait bounds are copied from `impl FromRequest for axum::extract::path::Path` diff --git a/examples/diesel-async-postgres/src/main.rs b/examples/diesel-async-postgres/src/main.rs index ee42ac1002b..d018bda100e 100644 --- a/examples/diesel-async-postgres/src/main.rs +++ b/examples/diesel-async-postgres/src/main.rs @@ -13,7 +13,6 @@ //! for a real world application using axum and diesel use axum::{ - async_trait, extract::{FromRef, FromRequestParts, State}, http::{request::Parts, StatusCode}, response::Json, @@ -102,7 +101,6 @@ struct DatabaseConnection( bb8::PooledConnection<'static, AsyncDieselConnectionManager>, ); -#[async_trait] impl FromRequestParts for DatabaseConnection where S: Send + Sync, diff --git a/examples/error-handling-and-dependency-injection/src/main.rs b/examples/error-handling-and-dependency-injection/src/main.rs index a5bdad9e6fa..df46f1fb70b 100644 --- a/examples/error-handling-and-dependency-injection/src/main.rs +++ b/examples/error-handling-and-dependency-injection/src/main.rs @@ -8,7 +8,6 @@ //! ``` use axum::{ - async_trait, extract::{Path, State}, http::StatusCode, response::{IntoResponse, Response}, @@ -109,7 +108,6 @@ impl IntoResponse for AppError { /// Example implementation of `UserRepo`. struct ExampleUserRepo; -#[async_trait] impl UserRepo for ExampleUserRepo { async fn find(&self, _user_id: Uuid) -> Result { unimplemented!() @@ -124,7 +122,6 @@ impl UserRepo for ExampleUserRepo { type DynUserRepo = Arc; /// A trait that defines things a user repo might support. -#[async_trait] trait UserRepo { /// Loop up a user by their id. async fn find(&self, user_id: Uuid) -> Result; diff --git a/examples/jwt/src/main.rs b/examples/jwt/src/main.rs index 85211851b2c..f39cb69698b 100644 --- a/examples/jwt/src/main.rs +++ b/examples/jwt/src/main.rs @@ -7,7 +7,6 @@ //! ``` use axum::{ - async_trait, extract::FromRequestParts, http::{request::Parts, StatusCode}, response::{IntoResponse, Response}, @@ -122,7 +121,6 @@ impl AuthBody { } } -#[async_trait] impl FromRequestParts for Claims where S: Send + Sync, diff --git a/examples/oauth/src/main.rs b/examples/oauth/src/main.rs index 6ceffe8f84e..880e7e25106 100644 --- a/examples/oauth/src/main.rs +++ b/examples/oauth/src/main.rs @@ -11,7 +11,6 @@ use anyhow::{Context, Result}; use async_session::{MemoryStore, Session, SessionStore}; use axum::{ - async_trait, extract::{FromRef, FromRequestParts, Query, State}, http::{header::SET_COOKIE, HeaderMap}, response::{IntoResponse, Redirect, Response}, @@ -249,7 +248,6 @@ impl IntoResponse for AuthRedirect { } } -#[async_trait] impl FromRequestParts for User where MemoryStore: FromRef, diff --git a/examples/parse-body-based-on-content-type/src/main.rs b/examples/parse-body-based-on-content-type/src/main.rs index bae4ec1d295..ced01252b00 100644 --- a/examples/parse-body-based-on-content-type/src/main.rs +++ b/examples/parse-body-based-on-content-type/src/main.rs @@ -7,7 +7,6 @@ //! ``` use axum::{ - async_trait, extract::{FromRequest, Request}, http::{header::CONTENT_TYPE, StatusCode}, response::{IntoResponse, Response}, @@ -48,7 +47,6 @@ async fn handler(JsonOrForm(payload): JsonOrForm) { struct JsonOrForm(T); -#[async_trait] impl FromRequest for JsonOrForm where S: Send + Sync, diff --git a/examples/sqlx-postgres/src/main.rs b/examples/sqlx-postgres/src/main.rs index 465711157e1..e92d1ea0e55 100644 --- a/examples/sqlx-postgres/src/main.rs +++ b/examples/sqlx-postgres/src/main.rs @@ -14,7 +14,6 @@ //! ``` use axum::{ - async_trait, extract::{FromRef, FromRequestParts, State}, http::{request::Parts, StatusCode}, routing::get, @@ -75,7 +74,6 @@ async fn using_connection_pool_extractor( // which setup is appropriate depends on your application struct DatabaseConnection(sqlx::pool::PoolConnection); -#[async_trait] impl FromRequestParts for DatabaseConnection where PgPool: FromRef, diff --git a/examples/tokio-postgres/src/main.rs b/examples/tokio-postgres/src/main.rs index effc032089b..c6f38085b0c 100644 --- a/examples/tokio-postgres/src/main.rs +++ b/examples/tokio-postgres/src/main.rs @@ -5,7 +5,6 @@ //! ``` use axum::{ - async_trait, extract::{FromRef, FromRequestParts, State}, http::{request::Parts, StatusCode}, routing::get, @@ -68,7 +67,6 @@ async fn using_connection_pool_extractor( // which setup is appropriate depends on your application struct DatabaseConnection(PooledConnection<'static, PostgresConnectionManager>); -#[async_trait] impl FromRequestParts for DatabaseConnection where ConnectionPool: FromRef, diff --git a/examples/validator/Cargo.toml b/examples/validator/Cargo.toml index a1adc075a8c..98d00cecf86 100644 --- a/examples/validator/Cargo.toml +++ b/examples/validator/Cargo.toml @@ -5,7 +5,6 @@ publish = false version = "0.1.0" [dependencies] -async-trait = "0.1.67" axum = { path = "../../axum" } http-body = "1.0.0" serde = { version = "1.0", features = ["derive"] } diff --git a/examples/validator/src/main.rs b/examples/validator/src/main.rs index 85c4ac18437..d2aa58073a7 100644 --- a/examples/validator/src/main.rs +++ b/examples/validator/src/main.rs @@ -10,7 +10,6 @@ //! ->

Hello, LT!

//! ``` -use async_trait::async_trait; use axum::{ extract::{rejection::FormRejection, Form, FromRequest, Request}, http::StatusCode, @@ -56,7 +55,6 @@ async fn handler(ValidatedForm(input): ValidatedForm) -> Html #[derive(Debug, Clone, Copy, Default)] pub struct ValidatedForm(pub T); -#[async_trait] impl FromRequest for ValidatedForm where T: DeserializeOwned + Validate, diff --git a/examples/versioning/src/main.rs b/examples/versioning/src/main.rs index a1d96e83404..f8317bf5bf9 100644 --- a/examples/versioning/src/main.rs +++ b/examples/versioning/src/main.rs @@ -5,7 +5,6 @@ //! ``` use axum::{ - async_trait, extract::{FromRequestParts, Path}, http::{request::Parts, StatusCode}, response::{IntoResponse, Response}, @@ -47,7 +46,6 @@ enum Version { V3, } -#[async_trait] impl FromRequestParts for Version where S: Send + Sync,