remove async_trait

This commit is contained in:
lz1998 2023-12-30 01:08:41 +08:00
parent c1c917092d
commit a160f98ac2
63 changed files with 95 additions and 259 deletions

View file

@ -18,7 +18,6 @@ tracing = ["dep:tracing"]
__private_docs = ["dep:tower-http"] __private_docs = ["dep:tower-http"]
[dependencies] [dependencies]
async-trait = "0.1.67"
bytes = "1.0" bytes = "1.0"
futures-util = { version = "0.3", default-features = false, features = ["alloc"] } futures-util = { version = "0.3", default-features = false, features = ["alloc"] }
http = "1.0.0" http = "1.0.0"

View file

@ -6,13 +6,11 @@ mod tests {
use std::convert::Infallible; use std::convert::Infallible;
use crate::extract::{FromRef, FromRequestParts}; use crate::extract::{FromRef, FromRequestParts};
use async_trait::async_trait;
use http::request::Parts; use http::request::Parts;
#[derive(Debug, Default, Clone, Copy)] #[derive(Debug, Default, Clone, Copy)]
pub(crate) struct State<S>(pub(crate) S); pub(crate) struct State<S>(pub(crate) S);
#[async_trait]
impl<OuterState, InnerState> FromRequestParts<OuterState> for State<InnerState> impl<OuterState, InnerState> FromRequestParts<OuterState> for State<InnerState>
where where
InnerState: FromRef<OuterState>, InnerState: FromRef<OuterState>,
@ -32,7 +30,6 @@ mod tests {
// some extractor that requires the state, such as `SignedCookieJar` // some extractor that requires the state, such as `SignedCookieJar`
pub(crate) struct RequiresState(pub(crate) String); pub(crate) struct RequiresState(pub(crate) String);
#[async_trait]
impl<S> FromRequestParts<S> for RequiresState impl<S> FromRequestParts<S> for RequiresState
where where
S: Send + Sync, S: Send + Sync,

View file

@ -1,6 +1,6 @@
use crate::body::Body; use crate::body::Body;
use crate::extract::{DefaultBodyLimitKind, FromRequest, FromRequestParts, Request}; use crate::extract::{DefaultBodyLimitKind, FromRequest, FromRequestParts, Request};
use futures_util::future::BoxFuture; use std::future::Future;
mod sealed { mod sealed {
pub trait Sealed {} pub trait Sealed {}
@ -20,7 +20,6 @@ pub trait RequestExt: sealed::Sealed + Sized {
/// ///
/// ``` /// ```
/// use axum::{ /// use axum::{
/// async_trait,
/// extract::{Request, FromRequest}, /// extract::{Request, FromRequest},
/// body::Body, /// body::Body,
/// http::{header::CONTENT_TYPE, StatusCode}, /// http::{header::CONTENT_TYPE, StatusCode},
@ -30,7 +29,6 @@ pub trait RequestExt: sealed::Sealed + Sized {
/// ///
/// struct FormOrJson<T>(T); /// struct FormOrJson<T>(T);
/// ///
/// #[async_trait]
/// impl<S, T> FromRequest<S> for FormOrJson<T> /// impl<S, T> FromRequest<S> for FormOrJson<T>
/// where /// where
/// Json<T>: FromRequest<()>, /// Json<T>: FromRequest<()>,
@ -67,7 +65,7 @@ pub trait RequestExt: sealed::Sealed + Sized {
/// } /// }
/// } /// }
/// ``` /// ```
fn extract<E, M>(self) -> BoxFuture<'static, Result<E, E::Rejection>> fn extract<E, M>(self) -> impl Future<Output = Result<E, E::Rejection>> + Send
where where
E: FromRequest<(), M> + 'static, E: FromRequest<(), M> + 'static,
M: 'static; M: 'static;
@ -83,7 +81,6 @@ pub trait RequestExt: sealed::Sealed + Sized {
/// ///
/// ``` /// ```
/// use axum::{ /// use axum::{
/// async_trait,
/// body::Body, /// body::Body,
/// extract::{Request, FromRef, FromRequest}, /// extract::{Request, FromRef, FromRequest},
/// RequestExt, /// RequestExt,
@ -93,7 +90,6 @@ pub trait RequestExt: sealed::Sealed + Sized {
/// requires_state: RequiresState, /// requires_state: RequiresState,
/// } /// }
/// ///
/// #[async_trait]
/// impl<S> FromRequest<S> for MyExtractor /// impl<S> FromRequest<S> for MyExtractor
/// where /// where
/// String: FromRef<S>, /// String: FromRef<S>,
@ -111,7 +107,6 @@ pub trait RequestExt: sealed::Sealed + Sized {
/// // some extractor that consumes the request body and requires state /// // some extractor that consumes the request body and requires state
/// struct RequiresState { /* ... */ } /// struct RequiresState { /* ... */ }
/// ///
/// #[async_trait]
/// impl<S> FromRequest<S> for RequiresState /// impl<S> FromRequest<S> for RequiresState
/// where /// where
/// String: FromRef<S>, /// String: FromRef<S>,
@ -124,7 +119,10 @@ pub trait RequestExt: sealed::Sealed + Sized {
/// # } /// # }
/// } /// }
/// ``` /// ```
fn extract_with_state<E, S, M>(self, state: &S) -> BoxFuture<'_, Result<E, E::Rejection>> fn extract_with_state<E, S, M>(
self,
state: &S,
) -> impl Future<Output = Result<E, E::Rejection>> + Send
where where
E: FromRequest<S, M> + 'static, E: FromRequest<S, M> + 'static,
S: Send + Sync; S: Send + Sync;
@ -137,7 +135,6 @@ pub trait RequestExt: sealed::Sealed + Sized {
/// ///
/// ``` /// ```
/// use axum::{ /// use axum::{
/// async_trait,
/// extract::{Path, Request, FromRequest}, /// extract::{Path, Request, FromRequest},
/// response::{IntoResponse, Response}, /// response::{IntoResponse, Response},
/// body::Body, /// body::Body,
@ -154,7 +151,6 @@ pub trait RequestExt: sealed::Sealed + Sized {
/// payload: T, /// payload: T,
/// } /// }
/// ///
/// #[async_trait]
/// impl<S, T> FromRequest<S> for MyExtractor<T> /// impl<S, T> FromRequest<S> for MyExtractor<T>
/// where /// where
/// S: Send + Sync, /// S: Send + Sync,
@ -179,7 +175,7 @@ pub trait RequestExt: sealed::Sealed + Sized {
/// } /// }
/// } /// }
/// ``` /// ```
fn extract_parts<E>(&mut self) -> BoxFuture<'_, Result<E, E::Rejection>> fn extract_parts<E>(&mut self) -> impl Future<Output = Result<E, E::Rejection>> + Send
where where
E: FromRequestParts<()> + 'static; E: FromRequestParts<()> + 'static;
@ -191,7 +187,6 @@ pub trait RequestExt: sealed::Sealed + Sized {
/// ///
/// ``` /// ```
/// use axum::{ /// use axum::{
/// async_trait,
/// extract::{Request, FromRef, FromRequest, FromRequestParts}, /// extract::{Request, FromRef, FromRequest, FromRequestParts},
/// http::request::Parts, /// http::request::Parts,
/// response::{IntoResponse, Response}, /// response::{IntoResponse, Response},
@ -204,7 +199,6 @@ pub trait RequestExt: sealed::Sealed + Sized {
/// payload: T, /// payload: T,
/// } /// }
/// ///
/// #[async_trait]
/// impl<S, T> FromRequest<S> for MyExtractor<T> /// impl<S, T> FromRequest<S> for MyExtractor<T>
/// where /// where
/// String: FromRef<S>, /// String: FromRef<S>,
@ -234,7 +228,6 @@ pub trait RequestExt: sealed::Sealed + Sized {
/// ///
/// struct RequiresState {} /// struct RequiresState {}
/// ///
/// #[async_trait]
/// impl<S> FromRequestParts<S> for RequiresState /// impl<S> FromRequestParts<S> for RequiresState
/// where /// where
/// String: FromRef<S>, /// String: FromRef<S>,
@ -250,7 +243,7 @@ pub trait RequestExt: sealed::Sealed + Sized {
fn extract_parts_with_state<'a, E, S>( fn extract_parts_with_state<'a, E, S>(
&'a mut self, &'a mut self,
state: &'a S, state: &'a S,
) -> BoxFuture<'a, Result<E, E::Rejection>> ) -> impl Future<Output = Result<E, E::Rejection>> + Send + 'a
where where
E: FromRequestParts<S> + 'static, E: FromRequestParts<S> + 'static,
S: Send + Sync; S: Send + Sync;
@ -267,7 +260,7 @@ pub trait RequestExt: sealed::Sealed + Sized {
} }
impl RequestExt for Request { impl RequestExt for Request {
fn extract<E, M>(self) -> BoxFuture<'static, Result<E, E::Rejection>> fn extract<E, M>(self) -> impl Future<Output = Result<E, E::Rejection>> + Send
where where
E: FromRequest<(), M> + 'static, E: FromRequest<(), M> + 'static,
M: 'static, M: 'static,
@ -275,7 +268,10 @@ impl RequestExt for Request {
self.extract_with_state(&()) self.extract_with_state(&())
} }
fn extract_with_state<E, S, M>(self, state: &S) -> BoxFuture<'_, Result<E, E::Rejection>> fn extract_with_state<E, S, M>(
self,
state: &S,
) -> impl Future<Output = Result<E, E::Rejection>> + Send
where where
E: FromRequest<S, M> + 'static, E: FromRequest<S, M> + 'static,
S: Send + Sync, S: Send + Sync,
@ -283,17 +279,17 @@ impl RequestExt for Request {
E::from_request(self, state) E::from_request(self, state)
} }
fn extract_parts<E>(&mut self) -> BoxFuture<'_, Result<E, E::Rejection>> fn extract_parts<E>(&mut self) -> impl Future<Output = Result<E, E::Rejection>> + Send
where where
E: FromRequestParts<()> + 'static, E: FromRequestParts<()> + 'static,
{ {
self.extract_parts_with_state(&()) 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, &'a mut self,
state: &'a S, state: &'a S,
) -> BoxFuture<'a, Result<E, E::Rejection>> ) -> Result<E, E::Rejection>
where where
E: FromRequestParts<S> + 'static, E: FromRequestParts<S> + 'static,
S: Send + Sync, S: Send + Sync,
@ -306,17 +302,15 @@ impl RequestExt for Request {
*req.extensions_mut() = std::mem::take(self.extensions_mut()); *req.extensions_mut() = std::mem::take(self.extensions_mut());
let (mut parts, ()) = req.into_parts(); 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.version_mut() = parts.version;
*self.method_mut() = parts.method.clone(); *self.method_mut() = parts.method.clone();
*self.uri_mut() = parts.uri.clone(); *self.uri_mut() = parts.uri.clone();
*self.headers_mut() = std::mem::take(&mut parts.headers); *self.headers_mut() = std::mem::take(&mut parts.headers);
*self.extensions_mut() = std::mem::take(&mut parts.extensions); *self.extensions_mut() = std::mem::take(&mut parts.extensions);
result result
})
} }
fn with_limited_body(self) -> Request { fn with_limited_body(self) -> Request {
@ -345,7 +339,6 @@ mod tests {
ext_traits::tests::{RequiresState, State}, ext_traits::tests::{RequiresState, State},
extract::FromRef, extract::FromRef,
}; };
use async_trait::async_trait;
use http::Method; use http::Method;
#[tokio::test] #[tokio::test]
@ -414,7 +407,6 @@ mod tests {
body: String, body: String,
} }
#[async_trait]
impl<S> FromRequest<S> for WorksForCustomExtractor impl<S> FromRequest<S> for WorksForCustomExtractor
where where
S: Send + Sync, S: Send + Sync,

View file

@ -1,6 +1,6 @@
use crate::extract::FromRequestParts; use crate::extract::FromRequestParts;
use futures_util::future::BoxFuture;
use http::request::Parts; use http::request::Parts;
use std::future::Future;
mod sealed { mod sealed {
pub trait Sealed {} pub trait Sealed {}
@ -21,7 +21,6 @@ pub trait RequestPartsExt: sealed::Sealed + Sized {
/// response::{Response, IntoResponse}, /// response::{Response, IntoResponse},
/// http::request::Parts, /// http::request::Parts,
/// RequestPartsExt, /// RequestPartsExt,
/// async_trait,
/// }; /// };
/// use std::collections::HashMap; /// use std::collections::HashMap;
/// ///
@ -30,7 +29,6 @@ pub trait RequestPartsExt: sealed::Sealed + Sized {
/// query_params: HashMap<String, String>, /// query_params: HashMap<String, String>,
/// } /// }
/// ///
/// #[async_trait]
/// impl<S> FromRequestParts<S> for MyExtractor /// impl<S> FromRequestParts<S> for MyExtractor
/// where /// where
/// S: Send + Sync, /// S: Send + Sync,
@ -54,7 +52,7 @@ pub trait RequestPartsExt: sealed::Sealed + Sized {
/// } /// }
/// } /// }
/// ``` /// ```
fn extract<E>(&mut self) -> BoxFuture<'_, Result<E, E::Rejection>> fn extract<E>(&mut self) -> impl Future<Output = Result<E, E::Rejection>> + Send
where where
E: FromRequestParts<()> + 'static; E: FromRequestParts<()> + 'static;
@ -70,14 +68,12 @@ pub trait RequestPartsExt: sealed::Sealed + Sized {
/// response::{Response, IntoResponse}, /// response::{Response, IntoResponse},
/// http::request::Parts, /// http::request::Parts,
/// RequestPartsExt, /// RequestPartsExt,
/// async_trait,
/// }; /// };
/// ///
/// struct MyExtractor { /// struct MyExtractor {
/// requires_state: RequiresState, /// requires_state: RequiresState,
/// } /// }
/// ///
/// #[async_trait]
/// impl<S> FromRequestParts<S> for MyExtractor /// impl<S> FromRequestParts<S> for MyExtractor
/// where /// where
/// String: FromRef<S>, /// String: FromRef<S>,
@ -97,7 +93,6 @@ pub trait RequestPartsExt: sealed::Sealed + Sized {
/// struct RequiresState { /* ... */ } /// struct RequiresState { /* ... */ }
/// ///
/// // some extractor that requires a `String` in the state /// // some extractor that requires a `String` in the state
/// #[async_trait]
/// impl<S> FromRequestParts<S> for RequiresState /// impl<S> FromRequestParts<S> for RequiresState
/// where /// where
/// String: FromRef<S>, /// String: FromRef<S>,
@ -113,14 +108,14 @@ pub trait RequestPartsExt: sealed::Sealed + Sized {
fn extract_with_state<'a, E, S>( fn extract_with_state<'a, E, S>(
&'a mut self, &'a mut self,
state: &'a S, state: &'a S,
) -> BoxFuture<'a, Result<E, E::Rejection>> ) -> impl Future<Output = Result<E, E::Rejection>> + Send + 'a
where where
E: FromRequestParts<S> + 'static, E: FromRequestParts<S> + 'static,
S: Send + Sync; S: Send + Sync;
} }
impl RequestPartsExt for Parts { impl RequestPartsExt for Parts {
fn extract<E>(&mut self) -> BoxFuture<'_, Result<E, E::Rejection>> fn extract<E>(&mut self) -> impl Future<Output = Result<E, E::Rejection>> + Send
where where
E: FromRequestParts<()> + 'static, E: FromRequestParts<()> + 'static,
{ {
@ -130,7 +125,7 @@ impl RequestPartsExt for Parts {
fn extract_with_state<'a, E, S>( fn extract_with_state<'a, E, S>(
&'a mut self, &'a mut self,
state: &'a S, state: &'a S,
) -> BoxFuture<'a, Result<E, E::Rejection>> ) -> impl Future<Output = Result<E, E::Rejection>> + Send + 'a
where where
E: FromRequestParts<S> + 'static, E: FromRequestParts<S> + 'static,
S: Send + Sync, S: Send + Sync,
@ -148,7 +143,6 @@ mod tests {
ext_traits::tests::{RequiresState, State}, ext_traits::tests::{RequiresState, State},
extract::FromRef, extract::FromRef,
}; };
use async_trait::async_trait;
use http::{Method, Request}; use http::{Method, Request};
#[tokio::test] #[tokio::test]
@ -181,7 +175,6 @@ mod tests {
from_state: String, from_state: String,
} }
#[async_trait]
impl<S> FromRequestParts<S> for WorksForCustomExtractor impl<S> FromRequestParts<S> for WorksForCustomExtractor
where where
S: Send + Sync, S: Send + Sync,

View file

@ -5,9 +5,9 @@
//! [`axum::extract`]: https://docs.rs/axum/0.7/axum/extract/index.html //! [`axum::extract`]: https://docs.rs/axum/0.7/axum/extract/index.html
use crate::{body::Body, response::IntoResponse}; use crate::{body::Body, response::IntoResponse};
use async_trait::async_trait;
use http::request::Parts; use http::request::Parts;
use std::convert::Infallible; use std::convert::Infallible;
use std::future::Future;
pub mod rejection; pub mod rejection;
@ -42,7 +42,6 @@ mod private {
/// See [`axum::extract`] for more general docs about extractors. /// See [`axum::extract`] for more general docs about extractors.
/// ///
/// [`axum::extract`]: https://docs.rs/axum/0.7/axum/extract/index.html /// [`axum::extract`]: https://docs.rs/axum/0.7/axum/extract/index.html
#[async_trait]
#[cfg_attr( #[cfg_attr(
nightly_error_messages, nightly_error_messages,
diagnostic::on_unimplemented( diagnostic::on_unimplemented(
@ -55,7 +54,10 @@ pub trait FromRequestParts<S>: Sized {
type Rejection: IntoResponse; type Rejection: IntoResponse;
/// Perform the extraction. /// Perform the extraction.
async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection>; fn from_request_parts(
parts: &mut Parts,
state: &S,
) -> impl Future<Output = Result<Self, Self::Rejection>> + Send;
} }
/// Types that can be created from requests. /// Types that can be created from requests.
@ -69,7 +71,6 @@ pub trait FromRequestParts<S>: Sized {
/// See [`axum::extract`] for more general docs about extractors. /// See [`axum::extract`] for more general docs about extractors.
/// ///
/// [`axum::extract`]: https://docs.rs/axum/0.7/axum/extract/index.html /// [`axum::extract`]: https://docs.rs/axum/0.7/axum/extract/index.html
#[async_trait]
#[cfg_attr( #[cfg_attr(
nightly_error_messages, nightly_error_messages,
diagnostic::on_unimplemented( diagnostic::on_unimplemented(
@ -82,10 +83,12 @@ pub trait FromRequest<S, M = private::ViaRequest>: Sized {
type Rejection: IntoResponse; type Rejection: IntoResponse;
/// Perform the extraction. /// Perform the extraction.
async fn from_request(req: Request, state: &S) -> Result<Self, Self::Rejection>; fn from_request(
req: Request,
state: &S,
) -> impl Future<Output = Result<Self, Self::Rejection>> + Send;
} }
#[async_trait]
impl<S, T> FromRequest<S, private::ViaParts> for T impl<S, T> FromRequest<S, private::ViaParts> for T
where where
S: Send + Sync, S: Send + Sync,
@ -99,7 +102,6 @@ where
} }
} }
#[async_trait]
impl<S, T> FromRequestParts<S> for Option<T> impl<S, T> FromRequestParts<S> for Option<T>
where where
T: FromRequestParts<S>, T: FromRequestParts<S>,
@ -115,7 +117,6 @@ where
} }
} }
#[async_trait]
impl<S, T> FromRequest<S> for Option<T> impl<S, T> FromRequest<S> for Option<T>
where where
T: FromRequest<S>, T: FromRequest<S>,
@ -128,7 +129,6 @@ where
} }
} }
#[async_trait]
impl<S, T> FromRequestParts<S> for Result<T, T::Rejection> impl<S, T> FromRequestParts<S> for Result<T, T::Rejection>
where where
T: FromRequestParts<S>, T: FromRequestParts<S>,
@ -141,7 +141,6 @@ where
} }
} }
#[async_trait]
impl<S, T> FromRequest<S> for Result<T, T::Rejection> impl<S, T> FromRequest<S> for Result<T, T::Rejection>
where where
T: FromRequest<S>, T: FromRequest<S>,

View file

@ -1,12 +1,10 @@
use super::{rejection::*, FromRequest, FromRequestParts, Request}; use super::{rejection::*, FromRequest, FromRequestParts, Request};
use crate::{body::Body, RequestExt}; use crate::{body::Body, RequestExt};
use async_trait::async_trait;
use bytes::Bytes; use bytes::Bytes;
use http::{request::Parts, Extensions, HeaderMap, Method, Uri, Version}; use http::{request::Parts, Extensions, HeaderMap, Method, Uri, Version};
use http_body_util::BodyExt; use http_body_util::BodyExt;
use std::convert::Infallible; use std::convert::Infallible;
#[async_trait]
impl<S> FromRequest<S> for Request impl<S> FromRequest<S> for Request
where where
S: Send + Sync, S: Send + Sync,
@ -18,7 +16,6 @@ where
} }
} }
#[async_trait]
impl<S> FromRequestParts<S> for Method impl<S> FromRequestParts<S> for Method
where where
S: Send + Sync, S: Send + Sync,
@ -30,7 +27,6 @@ where
} }
} }
#[async_trait]
impl<S> FromRequestParts<S> for Uri impl<S> FromRequestParts<S> for Uri
where where
S: Send + Sync, S: Send + Sync,
@ -42,7 +38,6 @@ where
} }
} }
#[async_trait]
impl<S> FromRequestParts<S> for Version impl<S> FromRequestParts<S> for Version
where where
S: Send + Sync, S: Send + Sync,
@ -59,7 +54,6 @@ where
/// Prefer using [`TypedHeader`] to extract only the headers you need. /// Prefer using [`TypedHeader`] to extract only the headers you need.
/// ///
/// [`TypedHeader`]: https://docs.rs/axum/0.7/axum/extract/struct.TypedHeader.html /// [`TypedHeader`]: https://docs.rs/axum/0.7/axum/extract/struct.TypedHeader.html
#[async_trait]
impl<S> FromRequestParts<S> for HeaderMap impl<S> FromRequestParts<S> for HeaderMap
where where
S: Send + Sync, S: Send + Sync,
@ -71,7 +65,6 @@ where
} }
} }
#[async_trait]
impl<S> FromRequest<S> for Bytes impl<S> FromRequest<S> for Bytes
where where
S: Send + Sync, S: Send + Sync,
@ -90,7 +83,6 @@ where
} }
} }
#[async_trait]
impl<S> FromRequest<S> for String impl<S> FromRequest<S> for String
where where
S: Send + Sync, S: Send + Sync,
@ -114,7 +106,6 @@ where
} }
} }
#[async_trait]
impl<S> FromRequestParts<S> for Parts impl<S> FromRequestParts<S> for Parts
where where
S: Send + Sync, S: Send + Sync,
@ -126,7 +117,6 @@ where
} }
} }
#[async_trait]
impl<S> FromRequestParts<S> for Extensions impl<S> FromRequestParts<S> for Extensions
where where
S: Send + Sync, S: Send + Sync,
@ -138,7 +128,6 @@ where
} }
} }
#[async_trait]
impl<S> FromRequest<S> for Body impl<S> FromRequest<S> for Body
where where
S: Send + Sync, S: Send + Sync,

View file

@ -1,10 +1,8 @@
use super::{FromRequest, FromRequestParts, Request}; use super::{FromRequest, FromRequestParts, Request};
use crate::response::{IntoResponse, Response}; use crate::response::{IntoResponse, Response};
use async_trait::async_trait;
use http::request::Parts; use http::request::Parts;
use std::convert::Infallible; use std::convert::Infallible;
#[async_trait]
impl<S> FromRequestParts<S> for () impl<S> FromRequestParts<S> for ()
where where
S: Send + Sync, S: Send + Sync,
@ -20,7 +18,6 @@ macro_rules! impl_from_request {
( (
[$($ty:ident),*], $last:ident [$($ty:ident),*], $last:ident
) => { ) => {
#[async_trait]
#[allow(non_snake_case, unused_mut, unused_variables)] #[allow(non_snake_case, unused_mut, unused_variables)]
impl<S, $($ty,)* $last> FromRequestParts<S> for ($($ty,)* $last,) impl<S, $($ty,)* $last> FromRequestParts<S> for ($($ty,)* $last,)
where 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 // This impl must not be generic over M, otherwise it would conflict with the blanket
// implementation of `FromRequest<S, Mut>` for `T: FromRequestParts<S>`. // implementation of `FromRequest<S, Mut>` for `T: FromRequestParts<S>`.
#[async_trait]
#[allow(non_snake_case, unused_mut, unused_variables)] #[allow(non_snake_case, unused_mut, unused_variables)]
impl<S, $($ty,)* $last> FromRequest<S> for ($($ty,)* $last,) impl<S, $($ty,)* $last> FromRequest<S> for ($($ty,)* $last,)
where where

View file

@ -7,7 +7,6 @@
//! use axum::{ //! use axum::{
//! body::Bytes, //! body::Bytes,
//! Router, //! Router,
//! async_trait,
//! routing::get, //! routing::get,
//! extract::FromRequestParts, //! extract::FromRequestParts,
//! }; //! };
@ -15,7 +14,6 @@
//! // extractors for checking permissions //! // extractors for checking permissions
//! struct AdminPermissions {} //! struct AdminPermissions {}
//! //!
//! #[async_trait]
//! impl<S> FromRequestParts<S> for AdminPermissions //! impl<S> FromRequestParts<S> for AdminPermissions
//! where //! where
//! S: Send + Sync, //! S: Send + Sync,
@ -29,7 +27,6 @@
//! //!
//! struct User {} //! struct User {}
//! //!
//! #[async_trait]
//! impl<S> FromRequestParts<S> for User //! impl<S> FromRequestParts<S> for User
//! where //! where
//! S: Send + Sync, //! S: Send + Sync,
@ -96,7 +93,6 @@
use std::task::{Context, Poll}; use std::task::{Context, Poll};
use axum::{ use axum::{
async_trait,
extract::FromRequestParts, extract::FromRequestParts,
response::{IntoResponse, Response}, response::{IntoResponse, Response},
}; };
@ -236,7 +232,6 @@ macro_rules! impl_traits_for_either {
[$($ident:ident),* $(,)?], [$($ident:ident),* $(,)?],
$last:ident $(,)? $last:ident $(,)?
) => { ) => {
#[async_trait]
impl<S, $($ident),*, $last> FromRequestParts<S> for $either<$($ident),*, $last> impl<S, $($ident),*, $last> FromRequestParts<S> for $either<$($ident),*, $last>
where where
$($ident: FromRequestParts<S>),*, $($ident: FromRequestParts<S>),*,
@ -247,12 +242,12 @@ macro_rules! impl_traits_for_either {
async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> { async fn from_request_parts(parts: &mut Parts, state: &S) -> Result<Self, Self::Rejection> {
$( $(
if let Ok(value) = FromRequestParts::from_request_parts(parts, state).await { if let Ok(value) = <$ident as FromRequestParts<S>>::from_request_parts(parts, state).await {
return Ok(Self::$ident(value)); return Ok(Self::$ident(value));
} }
)* )*
FromRequestParts::from_request_parts(parts, state).await.map(Self::$last) <$last as FromRequestParts<S>>::from_request_parts(parts, state).await.map(Self::$last)
} }
} }

View file

@ -1,7 +1,4 @@
use axum::{ use axum::extract::{Extension, FromRequestParts};
async_trait,
extract::{Extension, FromRequestParts},
};
use http::request::Parts; use http::request::Parts;
/// Cache results of other extractors. /// Cache results of other extractors.
@ -19,7 +16,6 @@ use http::request::Parts;
/// ```rust /// ```rust
/// use axum_extra::extract::Cached; /// use axum_extra::extract::Cached;
/// use axum::{ /// use axum::{
/// async_trait,
/// extract::FromRequestParts, /// extract::FromRequestParts,
/// response::{IntoResponse, Response}, /// response::{IntoResponse, Response},
/// http::{StatusCode, request::Parts}, /// http::{StatusCode, request::Parts},
@ -28,7 +24,6 @@ use http::request::Parts;
/// #[derive(Clone)] /// #[derive(Clone)]
/// struct Session { /* ... */ } /// struct Session { /* ... */ }
/// ///
/// #[async_trait]
/// impl<S> FromRequestParts<S> for Session /// impl<S> FromRequestParts<S> for Session
/// where /// where
/// S: Send + Sync, /// S: Send + Sync,
@ -43,7 +38,6 @@ use http::request::Parts;
/// ///
/// struct CurrentUser { /* ... */ } /// struct CurrentUser { /* ... */ }
/// ///
/// #[async_trait]
/// impl<S> FromRequestParts<S> for CurrentUser /// impl<S> FromRequestParts<S> for CurrentUser
/// where /// where
/// S: Send + Sync, /// S: Send + Sync,
@ -86,7 +80,6 @@ pub struct Cached<T>(pub T);
#[derive(Clone)] #[derive(Clone)]
struct CachedEntry<T>(T); struct CachedEntry<T>(T);
#[async_trait]
impl<S, T> FromRequestParts<S> for Cached<T> impl<S, T> FromRequestParts<S> for Cached<T>
where where
S: Send + Sync, S: Send + Sync,
@ -126,7 +119,6 @@ mod tests {
#[derive(Clone, Debug, PartialEq, Eq)] #[derive(Clone, Debug, PartialEq, Eq)]
struct Extractor(Instant); struct Extractor(Instant);
#[async_trait]
impl<S> FromRequestParts<S> for Extractor impl<S> FromRequestParts<S> for Extractor
where where
S: Send + Sync, S: Send + Sync,

View file

@ -3,7 +3,6 @@
//! See [`CookieJar`], [`SignedCookieJar`], and [`PrivateCookieJar`] for more details. //! See [`CookieJar`], [`SignedCookieJar`], and [`PrivateCookieJar`] for more details.
use axum::{ use axum::{
async_trait,
extract::FromRequestParts, extract::FromRequestParts,
response::{IntoResponse, IntoResponseParts, Response, ResponseParts}, response::{IntoResponse, IntoResponseParts, Response, ResponseParts},
}; };
@ -90,7 +89,6 @@ pub struct CookieJar {
jar: cookie::CookieJar, jar: cookie::CookieJar,
} }
#[async_trait]
impl<S> FromRequestParts<S> for CookieJar impl<S> FromRequestParts<S> for CookieJar
where where
S: Send + Sync, S: Send + Sync,

View file

@ -1,6 +1,5 @@
use super::{cookies_from_request, set_cookies, Cookie, Key}; use super::{cookies_from_request, set_cookies, Cookie, Key};
use axum::{ use axum::{
async_trait,
extract::{FromRef, FromRequestParts}, extract::{FromRef, FromRequestParts},
response::{IntoResponse, IntoResponseParts, Response, ResponseParts}, response::{IntoResponse, IntoResponseParts, Response, ResponseParts},
}; };
@ -122,7 +121,6 @@ impl<K> fmt::Debug for PrivateCookieJar<K> {
} }
} }
#[async_trait]
impl<S, K> FromRequestParts<S> for PrivateCookieJar<K> impl<S, K> FromRequestParts<S> for PrivateCookieJar<K>
where where
S: Send + Sync, S: Send + Sync,

View file

@ -1,6 +1,5 @@
use super::{cookies_from_request, set_cookies}; use super::{cookies_from_request, set_cookies};
use axum::{ use axum::{
async_trait,
extract::{FromRef, FromRequestParts}, extract::{FromRef, FromRequestParts},
response::{IntoResponse, IntoResponseParts, Response, ResponseParts}, response::{IntoResponse, IntoResponseParts, Response, ResponseParts},
}; };
@ -139,7 +138,6 @@ impl<K> fmt::Debug for SignedCookieJar<K> {
} }
} }
#[async_trait]
impl<S, K> FromRequestParts<S> for SignedCookieJar<K> impl<S, K> FromRequestParts<S> for SignedCookieJar<K>
where where
S: Send + Sync, S: Send + Sync,

View file

@ -1,5 +1,4 @@
use axum::{ use axum::{
async_trait,
extract::{rejection::RawFormRejection, FromRequest, RawForm, Request}, extract::{rejection::RawFormRejection, FromRequest, RawForm, Request},
response::{IntoResponse, Response}, response::{IntoResponse, Response},
Error, RequestExt, Error, RequestExt,
@ -44,7 +43,6 @@ pub struct Form<T>(pub T);
axum_core::__impl_deref!(Form); axum_core::__impl_deref!(Form);
#[async_trait]
impl<T, S> FromRequest<S> for Form<T> impl<T, S> FromRequest<S> for Form<T>
where where
T: DeserializeOwned, T: DeserializeOwned,

View file

@ -3,7 +3,6 @@
//! See [`Multipart`] for more details. //! See [`Multipart`] for more details.
use axum::{ use axum::{
async_trait,
body::{Body, Bytes}, body::{Body, Bytes},
extract::FromRequest, extract::FromRequest,
response::{IntoResponse, Response}, response::{IntoResponse, Response},
@ -90,7 +89,6 @@ pub struct Multipart {
inner: multer::Multipart<'static>, inner: multer::Multipart<'static>,
} }
#[async_trait]
impl<S> FromRequest<S> for Multipart impl<S> FromRequest<S> for Multipart
where where
S: Send + Sync, S: Send + Sync,

View file

@ -1,5 +1,4 @@
use axum::{ use axum::{
async_trait,
extract::{path::ErrorKind, rejection::PathRejection, FromRequestParts, Path}, extract::{path::ErrorKind, rejection::PathRejection, FromRequestParts, Path},
RequestPartsExt, RequestPartsExt,
}; };
@ -35,7 +34,6 @@ use serde::de::DeserializeOwned;
#[derive(Debug)] #[derive(Debug)]
pub struct OptionalPath<T>(pub Option<T>); pub struct OptionalPath<T>(pub Option<T>);
#[async_trait]
impl<T, S> FromRequestParts<S> for OptionalPath<T> impl<T, S> FromRequestParts<S> for OptionalPath<T>
where where
T: DeserializeOwned + Send + 'static, T: DeserializeOwned + Send + 'static,

View file

@ -1,5 +1,4 @@
use axum::{ use axum::{
async_trait,
extract::FromRequestParts, extract::FromRequestParts,
response::{IntoResponse, Response}, response::{IntoResponse, Response},
Error, Error,
@ -55,7 +54,6 @@ use std::fmt;
#[derive(Debug, Clone, Copy, Default)] #[derive(Debug, Clone, Copy, Default)]
pub struct Query<T>(pub T); pub struct Query<T>(pub T);
#[async_trait]
impl<T, S> FromRequestParts<S> for Query<T> impl<T, S> FromRequestParts<S> for Query<T>
where where
T: DeserializeOwned, T: DeserializeOwned,
@ -155,7 +153,6 @@ impl std::error::Error for QueryRejection {
#[derive(Debug, Clone, Copy, Default)] #[derive(Debug, Clone, Copy, Default)]
pub struct OptionalQuery<T>(pub Option<T>); pub struct OptionalQuery<T>(pub Option<T>);
#[async_trait]
impl<T, S> FromRequestParts<S> for OptionalQuery<T> impl<T, S> FromRequestParts<S> for OptionalQuery<T>
where where
T: DeserializeOwned, T: DeserializeOwned,

View file

@ -1,4 +1,3 @@
use axum::async_trait;
use axum::extract::{FromRequest, FromRequestParts, Request}; use axum::extract::{FromRequest, FromRequestParts, Request};
use axum::response::IntoResponse; use axum::response::IntoResponse;
use http::request::Parts; use http::request::Parts;
@ -107,7 +106,6 @@ impl<E, R> DerefMut for WithRejection<E, R> {
} }
} }
#[async_trait]
impl<E, R, S> FromRequest<S> for WithRejection<E, R> impl<E, R, S> FromRequest<S> for WithRejection<E, R>
where where
S: Send + Sync, S: Send + Sync,
@ -122,7 +120,6 @@ where
} }
} }
#[async_trait]
impl<E, R, S> FromRequestParts<S> for WithRejection<E, R> impl<E, R, S> FromRequestParts<S> for WithRejection<E, R>
where where
S: Send + Sync, S: Send + Sync,
@ -152,7 +149,6 @@ mod tests {
struct TestExtractor; struct TestExtractor;
struct TestRejection; struct TestRejection;
#[async_trait]
impl<S> FromRequestParts<S> for TestExtractor impl<S> FromRequestParts<S> for TestExtractor
where where
S: Send + Sync, S: Send + Sync,

View file

@ -47,7 +47,6 @@ pub trait HandlerCallWithExtractors<T, S>: Sized {
/// use axum_extra::handler::HandlerCallWithExtractors; /// use axum_extra::handler::HandlerCallWithExtractors;
/// use axum::{ /// use axum::{
/// Router, /// Router,
/// async_trait,
/// routing::get, /// routing::get,
/// extract::FromRequestParts, /// extract::FromRequestParts,
/// }; /// };
@ -68,7 +67,6 @@ pub trait HandlerCallWithExtractors<T, S>: Sized {
/// // extractors for checking permissions /// // extractors for checking permissions
/// struct AdminPermissions {} /// struct AdminPermissions {}
/// ///
/// #[async_trait]
/// impl<S> FromRequestParts<S> for AdminPermissions /// impl<S> FromRequestParts<S> for AdminPermissions
/// where /// where
/// S: Send + Sync, /// S: Send + Sync,
@ -82,7 +80,6 @@ pub trait HandlerCallWithExtractors<T, S>: Sized {
/// ///
/// struct User {} /// struct User {}
/// ///
/// #[async_trait]
/// impl<S> FromRequestParts<S> for User /// impl<S> FromRequestParts<S> for User
/// where /// where
/// S: Send + Sync, /// S: Send + Sync,

View file

@ -1,7 +1,6 @@
//! Newline delimited JSON extractor and response. //! Newline delimited JSON extractor and response.
use axum::{ use axum::{
async_trait,
body::Body, body::Body,
extract::{FromRequest, Request}, extract::{FromRequest, Request},
response::{IntoResponse, Response}, response::{IntoResponse, Response},
@ -99,7 +98,6 @@ impl<S> JsonLines<S, AsResponse> {
} }
} }
#[async_trait]
impl<S, T> FromRequest<S> for JsonLines<T, AsExtractor> impl<S, T> FromRequest<S> for JsonLines<T, AsExtractor>
where where
T: DeserializeOwned, T: DeserializeOwned,

View file

@ -1,7 +1,6 @@
//! Protocol Buffer extractor and response. //! Protocol Buffer extractor and response.
use axum::{ use axum::{
async_trait,
extract::{rejection::BytesRejection, FromRequest, Request}, extract::{rejection::BytesRejection, FromRequest, Request},
response::{IntoResponse, Response}, response::{IntoResponse, Response},
}; };
@ -90,7 +89,6 @@ use prost::Message;
#[must_use] #[must_use]
pub struct Protobuf<T>(pub T); pub struct Protobuf<T>(pub T);
#[async_trait]
impl<T, S> FromRequest<S> for Protobuf<T> impl<T, S> FromRequest<S> for Protobuf<T>
where where
T: Message + Default, T: Message + Default,

View file

@ -1,7 +1,6 @@
//! Extractor and response for typed headers. //! Extractor and response for typed headers.
use axum::{ use axum::{
async_trait,
extract::FromRequestParts, extract::FromRequestParts,
response::{IntoResponse, IntoResponseParts, Response, ResponseParts}, response::{IntoResponse, IntoResponseParts, Response, ResponseParts},
}; };
@ -55,7 +54,6 @@ use std::convert::Infallible;
#[must_use] #[must_use]
pub struct TypedHeader<T>(pub T); pub struct TypedHeader<T>(pub T);
#[async_trait]
impl<T, S> FromRequestParts<S> for TypedHeader<T> impl<T, S> FromRequestParts<S> for TypedHeader<T>
where where
T: Header, T: Header,

View file

@ -1 +1 @@
nightly-2023-09-23 nightly-2023-11-23

View file

@ -6,6 +6,7 @@ use crate::{
use proc_macro2::{Span, TokenStream}; use proc_macro2::{Span, TokenStream};
use quote::{quote, quote_spanned, ToTokens}; use quote::{quote, quote_spanned, ToTokens};
use std::{collections::HashSet, fmt, iter}; use std::{collections::HashSet, fmt, iter};
use syn::token::Comma;
use syn::{ use syn::{
parse_quote, punctuated::Punctuated, spanned::Spanned, Fields, Ident, Path, Token, Type, parse_quote, punctuated::Punctuated, spanned::Spanned, Fields, Ident, Path, Token, Type,
}; };
@ -339,12 +340,16 @@ fn impl_struct_by_extracting_each_field(
state: &State, state: &State,
tr: Trait, tr: Trait,
) -> syn::Result<TokenStream> { ) -> syn::Result<TokenStream> {
let trait_generics = state
.trait_generics()
.collect::<Punctuated<Type, Token![,]>>();
let trait_fn_body = match state { let trait_fn_body = match state {
State::CannotInfer => quote! { State::CannotInfer => quote! {
::std::unimplemented!() ::std::unimplemented!()
}, },
_ => { _ => {
let extract_fields = extract_fields(&fields, &rejection, tr)?; let extract_fields = extract_fields(&fields, &rejection, tr, &trait_generics)?;
quote! { quote! {
::std::result::Result::Ok(Self { ::std::result::Result::Ok(Self {
#(#extract_fields)* #(#extract_fields)*
@ -365,15 +370,10 @@ fn impl_struct_by_extracting_each_field(
.impl_generics() .impl_generics()
.collect::<Punctuated<Type, Token![,]>>(); .collect::<Punctuated<Type, Token![,]>>();
let trait_generics = state
.trait_generics()
.collect::<Punctuated<Type, Token![,]>>();
let state_bounds = state.bounds(); let state_bounds = state.bounds();
Ok(match tr { Ok(match tr {
Trait::FromRequest => quote! { Trait::FromRequest => quote! {
#[::axum::async_trait]
#[automatically_derived] #[automatically_derived]
impl<#impl_generics> ::axum::extract::FromRequest<#trait_generics> for #ident impl<#impl_generics> ::axum::extract::FromRequest<#trait_generics> for #ident
where where
@ -390,7 +390,6 @@ fn impl_struct_by_extracting_each_field(
} }
}, },
Trait::FromRequestParts => quote! { Trait::FromRequestParts => quote! {
#[::axum::async_trait]
#[automatically_derived] #[automatically_derived]
impl<#impl_generics> ::axum::extract::FromRequestParts<#trait_generics> for #ident impl<#impl_generics> ::axum::extract::FromRequestParts<#trait_generics> for #ident
where where
@ -421,6 +420,7 @@ fn extract_fields(
fields: &syn::Fields, fields: &syn::Fields,
rejection: &Option<syn::Path>, rejection: &Option<syn::Path>,
tr: Trait, tr: Trait,
trait_generics: &Punctuated<Type, Comma>,
) -> syn::Result<Vec<TokenStream>> { ) -> syn::Result<Vec<TokenStream>> {
fn member(field: &syn::Field, index: usize) -> TokenStream { fn member(field: &syn::Field, index: usize) -> TokenStream {
match &field.ident { match &field.ident {
@ -435,7 +435,7 @@ fn extract_fields(
} }
} }
fn into_inner(via: Option<(attr::kw::via, syn::Path)>, ty_span: Span) -> TokenStream { fn into_inner(via: &Option<(attr::kw::via, syn::Path)>, ty_span: Span) -> TokenStream {
if let Some((_, path)) = via { if let Some((_, path)) = via {
let span = path.span(); let span = path.span();
quote_spanned! {span=> quote_spanned! {span=>
@ -448,6 +448,23 @@ fn extract_fields(
} }
} }
fn into_outer(
via: &Option<(attr::kw::via, syn::Path)>,
ty_span: Span,
field_ty: &Type,
) -> TokenStream {
if let Some((_, path)) = via {
let span = path.span();
quote_spanned! {span=>
#path<#field_ty>
}
} else {
quote_spanned! {ty_span=>
#field_ty
}
}
}
let mut fields_iter = fields.iter(); let mut fields_iter = fields.iter();
let last = match tr { let last = match tr {
@ -464,16 +481,17 @@ fn extract_fields(
let member = member(field, index); let member = member(field, index);
let ty_span = field.ty.span(); let ty_span = field.ty.span();
let into_inner = into_inner(via, ty_span); let into_inner = into_inner(&via, ty_span);
if peel_option(&field.ty).is_some() { if peel_option(&field.ty).is_some() {
let field_ty = into_outer(&via, ty_span, peel_option(&field.ty).unwrap());
let tokens = match tr { let tokens = match tr {
Trait::FromRequest => { Trait::FromRequest => {
quote_spanned! {ty_span=> quote_spanned! {ty_span=>
#member: { #member: {
let (mut parts, body) = req.into_parts(); let (mut parts, body) = req.into_parts();
let value = let value =
::axum::extract::FromRequestParts::from_request_parts( <#field_ty as ::axum::extract::FromRequestParts<#trait_generics>>::from_request_parts(
&mut parts, &mut parts,
state, state,
) )
@ -488,7 +506,7 @@ fn extract_fields(
Trait::FromRequestParts => { Trait::FromRequestParts => {
quote_spanned! {ty_span=> quote_spanned! {ty_span=>
#member: { #member: {
::axum::extract::FromRequestParts::from_request_parts( <#field_ty as ::axum::extract::FromRequestParts<#trait_generics>>::from_request_parts(
parts, parts,
state, state,
) )
@ -501,13 +519,14 @@ fn extract_fields(
}; };
Ok(tokens) Ok(tokens)
} else if peel_result_ok(&field.ty).is_some() { } else if peel_result_ok(&field.ty).is_some() {
let field_ty = into_outer(&via,ty_span, peel_result_ok(&field.ty).unwrap());
let tokens = match tr { let tokens = match tr {
Trait::FromRequest => { Trait::FromRequest => {
quote_spanned! {ty_span=> quote_spanned! {ty_span=>
#member: { #member: {
let (mut parts, body) = req.into_parts(); let (mut parts, body) = req.into_parts();
let value = let value =
::axum::extract::FromRequestParts::from_request_parts( <#field_ty as ::axum::extract::FromRequestParts<#trait_generics>>::from_request_parts(
&mut parts, &mut parts,
state, state,
) )
@ -521,7 +540,7 @@ fn extract_fields(
Trait::FromRequestParts => { Trait::FromRequestParts => {
quote_spanned! {ty_span=> quote_spanned! {ty_span=>
#member: { #member: {
::axum::extract::FromRequestParts::from_request_parts( <#field_ty as ::axum::extract::FromRequestParts<#trait_generics>>::from_request_parts(
parts, parts,
state, state,
) )
@ -533,6 +552,7 @@ fn extract_fields(
}; };
Ok(tokens) Ok(tokens)
} else { } else {
let field_ty = into_outer(&via,ty_span,&field.ty);
let map_err = if let Some(rejection) = rejection { let map_err = if let Some(rejection) = rejection {
quote! { <#rejection as ::std::convert::From<_>>::from } quote! { <#rejection as ::std::convert::From<_>>::from }
} else { } else {
@ -545,7 +565,7 @@ fn extract_fields(
#member: { #member: {
let (mut parts, body) = req.into_parts(); let (mut parts, body) = req.into_parts();
let value = let value =
::axum::extract::FromRequestParts::from_request_parts( <#field_ty as ::axum::extract::FromRequestParts<#trait_generics>>::from_request_parts(
&mut parts, &mut parts,
state, state,
) )
@ -560,7 +580,7 @@ fn extract_fields(
Trait::FromRequestParts => { Trait::FromRequestParts => {
quote_spanned! {ty_span=> quote_spanned! {ty_span=>
#member: { #member: {
::axum::extract::FromRequestParts::from_request_parts( <#field_ty as ::axum::extract::FromRequestParts<#trait_generics>>::from_request_parts(
parts, parts,
state, state,
) )
@ -582,26 +602,29 @@ fn extract_fields(
let member = member(field, fields.len() - 1); let member = member(field, fields.len() - 1);
let ty_span = field.ty.span(); let ty_span = field.ty.span();
let into_inner = into_inner(via, ty_span); let into_inner = into_inner(&via, ty_span);
let item = if peel_option(&field.ty).is_some() { let item = if peel_option(&field.ty).is_some() {
let field_ty = into_outer(&via, ty_span, peel_option(&field.ty).unwrap());
quote_spanned! {ty_span=> quote_spanned! {ty_span=>
#member: { #member: {
::axum::extract::FromRequest::from_request(req, state) <#field_ty as ::axum::extract::FromRequest<#trait_generics>>::from_request(req, state)
.await .await
.ok() .ok()
.map(#into_inner) .map(#into_inner)
}, },
} }
} else if peel_result_ok(&field.ty).is_some() { } else if peel_result_ok(&field.ty).is_some() {
let field_ty = into_outer(&via, ty_span, peel_result_ok(&field.ty).unwrap());
quote_spanned! {ty_span=> quote_spanned! {ty_span=>
#member: { #member: {
::axum::extract::FromRequest::from_request(req, state) <#field_ty as ::axum::extract::FromRequest<#trait_generics>>::from_request(req, state)
.await .await
.map(#into_inner) .map(#into_inner)
}, },
} }
} else { } else {
let field_ty = into_outer(&via, ty_span, &field.ty);
let map_err = if let Some(rejection) = rejection { let map_err = if let Some(rejection) = rejection {
quote! { <#rejection as ::std::convert::From<_>>::from } quote! { <#rejection as ::std::convert::From<_>>::from }
} else { } else {
@ -610,7 +633,7 @@ fn extract_fields(
quote_spanned! {ty_span=> quote_spanned! {ty_span=>
#member: { #member: {
::axum::extract::FromRequest::from_request(req, state) <#field_ty as ::axum::extract::FromRequest<#trait_generics>>::from_request(req, state)
.await .await
.map(#into_inner) .map(#into_inner)
.map_err(#map_err)? .map_err(#map_err)?
@ -807,7 +830,6 @@ fn impl_struct_by_extracting_all_at_once(
let tokens = match tr { let tokens = match tr {
Trait::FromRequest => { Trait::FromRequest => {
quote_spanned! {path_span=> quote_spanned! {path_span=>
#[::axum::async_trait]
#[automatically_derived] #[automatically_derived]
impl<#impl_generics> ::axum::extract::FromRequest<#trait_generics> for #ident #ident_generics impl<#impl_generics> ::axum::extract::FromRequest<#trait_generics> for #ident #ident_generics
where where
@ -821,7 +843,7 @@ fn impl_struct_by_extracting_all_at_once(
req: ::axum::http::Request<::axum::body::Body>, req: ::axum::http::Request<::axum::body::Body>,
state: &#state, state: &#state,
) -> ::std::result::Result<Self, Self::Rejection> { ) -> ::std::result::Result<Self, Self::Rejection> {
::axum::extract::FromRequest::from_request(req, state) <#via_path<#via_type_generics> as ::axum::extract::FromRequest<#trait_generics>>::from_request(req, state)
.await .await
.map(|#via_path(value)| #value_to_self) .map(|#via_path(value)| #value_to_self)
.map_err(#map_err) .map_err(#map_err)
@ -831,7 +853,6 @@ fn impl_struct_by_extracting_all_at_once(
} }
Trait::FromRequestParts => { Trait::FromRequestParts => {
quote_spanned! {path_span=> quote_spanned! {path_span=>
#[::axum::async_trait]
#[automatically_derived] #[automatically_derived]
impl<#impl_generics> ::axum::extract::FromRequestParts<#trait_generics> for #ident #ident_generics impl<#impl_generics> ::axum::extract::FromRequestParts<#trait_generics> for #ident #ident_generics
where where
@ -845,7 +866,7 @@ fn impl_struct_by_extracting_all_at_once(
parts: &mut ::axum::http::request::Parts, parts: &mut ::axum::http::request::Parts,
state: &#state, state: &#state,
) -> ::std::result::Result<Self, Self::Rejection> { ) -> ::std::result::Result<Self, Self::Rejection> {
::axum::extract::FromRequestParts::from_request_parts(parts, state) <#via_path<#via_type_generics> as ::axum::extract::FromRequestParts<#trait_generics>>::from_request_parts(parts, state)
.await .await
.map(|#via_path(value)| #value_to_self) .map(|#via_path(value)| #value_to_self)
.map_err(#map_err) .map_err(#map_err)
@ -920,7 +941,6 @@ fn impl_enum_by_extracting_all_at_once(
let tokens = match tr { let tokens = match tr {
Trait::FromRequest => { Trait::FromRequest => {
quote_spanned! {path_span=> quote_spanned! {path_span=>
#[::axum::async_trait]
#[automatically_derived] #[automatically_derived]
impl<#impl_generics> ::axum::extract::FromRequest<#trait_generics> for #ident impl<#impl_generics> ::axum::extract::FromRequest<#trait_generics> for #ident
where where
@ -932,7 +952,7 @@ fn impl_enum_by_extracting_all_at_once(
req: ::axum::http::Request<::axum::body::Body>, req: ::axum::http::Request<::axum::body::Body>,
state: &#state, state: &#state,
) -> ::std::result::Result<Self, Self::Rejection> { ) -> ::std::result::Result<Self, Self::Rejection> {
::axum::extract::FromRequest::from_request(req, state) <#path::<#ident> as ::axum::extract::FromRequest<#trait_generics>>::from_request(req, state)
.await .await
.map(|#path(inner)| inner) .map(|#path(inner)| inner)
.map_err(#map_err) .map_err(#map_err)
@ -942,7 +962,6 @@ fn impl_enum_by_extracting_all_at_once(
} }
Trait::FromRequestParts => { Trait::FromRequestParts => {
quote_spanned! {path_span=> quote_spanned! {path_span=>
#[::axum::async_trait]
#[automatically_derived] #[automatically_derived]
impl<#impl_generics> ::axum::extract::FromRequestParts<#trait_generics> for #ident impl<#impl_generics> ::axum::extract::FromRequestParts<#trait_generics> for #ident
where where
@ -954,7 +973,7 @@ fn impl_enum_by_extracting_all_at_once(
parts: &mut ::axum::http::request::Parts, parts: &mut ::axum::http::request::Parts,
state: &#state, state: &#state,
) -> ::std::result::Result<Self, Self::Rejection> { ) -> ::std::result::Result<Self, Self::Rejection> {
::axum::extract::FromRequestParts::from_request_parts(parts, state) <#path::<#ident> as FromRequestParts<#trait_generics>>::from_request_parts(parts, state)
.await .await
.map(|#path(inner)| inner) .map(|#path(inner)| inner)
.map_err(#map_err) .map_err(#map_err)

View file

@ -133,7 +133,6 @@ fn expand_named_fields(
let map_err_rejection = map_err_rejection(&rejection); let map_err_rejection = map_err_rejection(&rejection);
let from_request_impl = quote! { let from_request_impl = quote! {
#[::axum::async_trait]
#[automatically_derived] #[automatically_derived]
impl<S> ::axum::extract::FromRequestParts<S> for #ident impl<S> ::axum::extract::FromRequestParts<S> for #ident
where where
@ -238,7 +237,6 @@ fn expand_unnamed_fields(
let map_err_rejection = map_err_rejection(&rejection); let map_err_rejection = map_err_rejection(&rejection);
let from_request_impl = quote! { let from_request_impl = quote! {
#[::axum::async_trait]
#[automatically_derived] #[automatically_derived]
impl<S> ::axum::extract::FromRequestParts<S> for #ident impl<S> ::axum::extract::FromRequestParts<S> for #ident
where where
@ -322,7 +320,6 @@ fn expand_unit_fields(
}; };
let from_request_impl = quote! { let from_request_impl = quote! {
#[::axum::async_trait]
#[automatically_derived] #[automatically_derived]
impl<S> ::axum::extract::FromRequestParts<S> for #ident impl<S> ::axum::extract::FromRequestParts<S> for #ident
where where

View file

@ -1,12 +1,8 @@
use axum::{ use axum::extract::{FromRequest, Request};
async_trait,
extract::{Request, FromRequest},
};
use axum_macros::debug_handler; use axum_macros::debug_handler;
struct A; struct A;
#[async_trait]
impl<S> FromRequest<S> for A impl<S> FromRequest<S> for A
where where
S: Send + Sync, S: Send + Sync,

View file

@ -1,12 +1,8 @@
use axum::{ use axum::extract::{FromRequest, Request};
async_trait,
extract::{Request, FromRequest},
};
use axum_macros::debug_handler; use axum_macros::debug_handler;
struct A; struct A;
#[async_trait]
impl<S> FromRequest<S> for A impl<S> FromRequest<S> for A
where where
S: Send + Sync, S: Send + Sync,

View file

@ -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; use axum_macros::debug_handler;
fn main() {} fn main() {}
@ -115,7 +115,6 @@ impl A {
} }
} }
#[async_trait]
impl<S> FromRequestParts<S> for A impl<S> FromRequestParts<S> for A
where where
S: Send + Sync, S: Send + Sync,

View file

@ -1,12 +1,8 @@
use axum::{ use axum::extract::{FromRequest, Request};
async_trait,
extract::{Request, FromRequest},
};
use axum_macros::debug_handler; use axum_macros::debug_handler;
struct A; struct A;
#[async_trait]
impl<S> FromRequest<S> for A impl<S> FromRequest<S> for A
where where
S: Send + Sync, S: Send + Sync,
@ -18,7 +14,6 @@ where
} }
} }
#[async_trait]
impl<S> FromRequest<S> for Box<A> impl<S> FromRequest<S> for Box<A>
where where
S: Send + Sync, S: Send + Sync,

View file

@ -1,6 +1,5 @@
use axum::extract::{FromRef, FromRequest, Request};
use axum_macros::debug_handler; use axum_macros::debug_handler;
use axum::extract::{Request, FromRef, FromRequest};
use axum::async_trait;
#[debug_handler(state = AppState)] #[debug_handler(state = AppState)]
async fn handler(_: A) {} async fn handler(_: A) {}
@ -10,7 +9,6 @@ struct AppState;
struct A; struct A;
#[async_trait]
impl<S> FromRequest<S> for A impl<S> FromRequest<S> for A
where where
S: Send + Sync, S: Send + Sync,

View file

@ -1,10 +1,9 @@
use axum::{ use axum::{
async_trait, body::Body,
extract::{Request, rejection::ExtensionRejection, FromRequest}, extract::{rejection::ExtensionRejection, FromRequest, Request},
http::StatusCode, http::StatusCode,
response::{IntoResponse, Response}, response::{IntoResponse, Response},
routing::get, routing::get,
body::Body,
Extension, Router, Extension, Router,
}; };
@ -27,7 +26,6 @@ struct MyExtractor {
struct OtherExtractor; struct OtherExtractor;
#[async_trait]
impl<S> FromRequest<S> for OtherExtractor impl<S> FromRequest<S> for OtherExtractor
where where
S: Send + Sync, S: Send + Sync,

View file

@ -1,5 +1,4 @@
use axum::{ use axum::{
async_trait,
extract::{rejection::ExtensionRejection, FromRequestParts}, extract::{rejection::ExtensionRejection, FromRequestParts},
http::{request::Parts, StatusCode}, http::{request::Parts, StatusCode},
response::{IntoResponse, Response}, response::{IntoResponse, Response},
@ -26,7 +25,6 @@ struct MyExtractor {
struct OtherExtractor; struct OtherExtractor;
#[async_trait]
impl<S> FromRequestParts<S> for OtherExtractor impl<S> FromRequestParts<S> for OtherExtractor
where where
S: Send + Sync, S: Send + Sync,

View file

@ -577,7 +577,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
```rust ```rust
struct MyExtractor { /* ... */ } struct MyExtractor { /* ... */ }
#[async_trait]
impl<B> FromRequest<B> for MyExtractor impl<B> FromRequest<B> for MyExtractor
where where
B: Send, B: Send,
@ -596,13 +595,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
use axum::{ use axum::{
extract::{FromRequest, FromRequestParts}, extract::{FromRequest, FromRequestParts},
http::{StatusCode, Request, request::Parts}, http::{StatusCode, Request, request::Parts},
async_trait,
}; };
struct MyExtractor { /* ... */ } struct MyExtractor { /* ... */ }
// implement `FromRequestParts` if you don't need to consume the request body // implement `FromRequestParts` if you don't need to consume the request body
#[async_trait]
impl<S> FromRequestParts<S> for MyExtractor impl<S> FromRequestParts<S> for MyExtractor
where where
S: Send + Sync, S: Send + Sync,
@ -615,7 +612,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 // implement `FromRequest` if you do need to consume the request body
#[async_trait]
impl<S, B> FromRequest<S, B> for MyExtractor impl<S, B> FromRequest<S, B> for MyExtractor
where where
S: Send + Sync, S: Send + Sync,
@ -1163,7 +1159,6 @@ Yanked, as it didn't compile in release mode.
```rust ```rust
struct MyExtractor { /* ... */ } struct MyExtractor { /* ... */ }
#[async_trait]
impl<B> FromRequest<B> for MyExtractor impl<B> FromRequest<B> for MyExtractor
where where
B: Send, B: Send,
@ -1182,13 +1177,11 @@ Yanked, as it didn't compile in release mode.
use axum::{ use axum::{
extract::{FromRequest, FromRequestParts}, extract::{FromRequest, FromRequestParts},
http::{StatusCode, Request, request::Parts}, http::{StatusCode, Request, request::Parts},
async_trait,
}; };
struct MyExtractor { /* ... */ } struct MyExtractor { /* ... */ }
// implement `FromRequestParts` if you don't need to consume the request body // implement `FromRequestParts` if you don't need to consume the request body
#[async_trait]
impl<S> FromRequestParts<S> for MyExtractor impl<S> FromRequestParts<S> for MyExtractor
where where
S: Send + Sync, S: Send + Sync,
@ -1201,7 +1194,6 @@ Yanked, as it didn't compile in release mode.
} }
// implement `FromRequest` if you do need to consume the request body // implement `FromRequest` if you do need to consume the request body
#[async_trait]
impl<S, B> FromRequest<S, B> for MyExtractor impl<S, B> FromRequest<S, B> for MyExtractor
where where
S: Send + Sync, S: Send + Sync,

View file

@ -41,7 +41,6 @@ ws = ["dep:hyper", "tokio", "dep:tokio-tungstenite", "dep:sha1", "dep:base64"]
__private_docs = ["tower/full", "dep:tower-http"] __private_docs = ["tower/full", "dep:tower-http"]
[dependencies] [dependencies]
async-trait = "0.1.67"
axum-core = { path = "../axum-core", version = "0.4.2" } axum-core = { path = "../axum-core", version = "0.4.2" }
bytes = "1.0" bytes = "1.0"
futures-util = { version = "0.3", default-features = false, features = ["alloc"] } futures-util = { version = "0.3", default-features = false, features = ["alloc"] }
@ -201,7 +200,6 @@ allowed = [
"tower_service", "tower_service",
# >=1.0 # >=1.0
"async_trait",
"bytes", "bytes",
"http", "http",
"http_body", "http_body",

View file

@ -421,7 +421,6 @@ request body:
```rust,no_run ```rust,no_run
use axum::{ use axum::{
async_trait,
extract::FromRequestParts, extract::FromRequestParts,
routing::get, routing::get,
Router, Router,
@ -434,7 +433,6 @@ use axum::{
struct ExtractUserAgent(HeaderValue); struct ExtractUserAgent(HeaderValue);
#[async_trait]
impl<S> FromRequestParts<S> for ExtractUserAgent impl<S> FromRequestParts<S> for ExtractUserAgent
where where
S: Send + Sync, S: Send + Sync,
@ -464,7 +462,6 @@ If your extractor needs to consume the request body you must implement [`FromReq
```rust,no_run ```rust,no_run
use axum::{ use axum::{
async_trait,
extract::{Request, FromRequest}, extract::{Request, FromRequest},
response::{Response, IntoResponse}, response::{Response, IntoResponse},
body::{Bytes, Body}, body::{Bytes, Body},
@ -478,7 +475,6 @@ use axum::{
struct ValidatedBody(Bytes); struct ValidatedBody(Bytes);
#[async_trait]
impl<S> FromRequest<S> for ValidatedBody impl<S> FromRequest<S> for ValidatedBody
where where
Bytes: FromRequest<S>, Bytes: FromRequest<S>,
@ -518,7 +514,6 @@ use axum::{
extract::{FromRequest, Request, FromRequestParts}, extract::{FromRequest, Request, FromRequestParts},
http::request::Parts, http::request::Parts,
body::Body, body::Body,
async_trait,
}; };
use std::convert::Infallible; use std::convert::Infallible;
@ -526,7 +521,6 @@ use std::convert::Infallible;
struct MyExtractor; struct MyExtractor;
// `MyExtractor` implements both `FromRequest` // `MyExtractor` implements both `FromRequest`
#[async_trait]
impl<S> FromRequest<S> for MyExtractor impl<S> FromRequest<S> for MyExtractor
where where
S: Send + Sync, S: Send + Sync,
@ -540,7 +534,6 @@ where
} }
// and `FromRequestParts` // and `FromRequestParts`
#[async_trait]
impl<S> FromRequestParts<S> for MyExtractor impl<S> FromRequestParts<S> for MyExtractor
where where
S: Send + Sync, S: Send + Sync,
@ -574,7 +567,6 @@ in your implementation.
```rust ```rust
use axum::{ use axum::{
async_trait,
extract::{Extension, FromRequestParts}, extract::{Extension, FromRequestParts},
http::{StatusCode, HeaderMap, request::Parts}, http::{StatusCode, HeaderMap, request::Parts},
response::{IntoResponse, Response}, response::{IntoResponse, Response},
@ -591,7 +583,6 @@ struct AuthenticatedUser {
// ... // ...
} }
#[async_trait]
impl<S> FromRequestParts<S> for AuthenticatedUser impl<S> FromRequestParts<S> for AuthenticatedUser
where where
S: Send + Sync, S: Send + Sync,
@ -645,7 +636,6 @@ use axum::{
routing::get, routing::get,
extract::{Request, FromRequest, FromRequestParts}, extract::{Request, FromRequest, FromRequestParts},
http::{HeaderMap, request::Parts}, http::{HeaderMap, request::Parts},
async_trait,
}; };
use std::time::{Instant, Duration}; use std::time::{Instant, Duration};
@ -656,7 +646,6 @@ struct Timing<E> {
} }
// we must implement both `FromRequestParts` // we must implement both `FromRequestParts`
#[async_trait]
impl<S, T> FromRequestParts<S> for Timing<T> impl<S, T> FromRequestParts<S> for Timing<T>
where where
S: Send + Sync, S: Send + Sync,
@ -676,7 +665,6 @@ where
} }
// and `FromRequest` // and `FromRequest`
#[async_trait]
impl<S, T> FromRequest<S> for Timing<T> impl<S, T> FromRequest<S> for Timing<T>
where where
S: Send + Sync, S: Send + Sync,

View file

@ -1,5 +1,4 @@
use crate::{extract::rejection::*, response::IntoResponseParts}; use crate::{extract::rejection::*, response::IntoResponseParts};
use async_trait::async_trait;
use axum_core::{ use axum_core::{
extract::FromRequestParts, extract::FromRequestParts,
response::{IntoResponse, Response, ResponseParts}, response::{IntoResponse, Response, ResponseParts},
@ -70,7 +69,6 @@ use tower_service::Service;
#[must_use] #[must_use]
pub struct Extension<T>(pub T); pub struct Extension<T>(pub T);
#[async_trait]
impl<T, S> FromRequestParts<S> for Extension<T> impl<T, S> FromRequestParts<S> for Extension<T>
where where
T: Clone + Send + Sync + 'static, T: Clone + Send + Sync + 'static,

View file

@ -7,7 +7,6 @@
use crate::extension::AddExtension; use crate::extension::AddExtension;
use super::{Extension, FromRequestParts}; use super::{Extension, FromRequestParts};
use async_trait::async_trait;
use http::request::Parts; use http::request::Parts;
use std::{ use std::{
convert::Infallible, convert::Infallible,
@ -139,7 +138,6 @@ opaque_future! {
#[derive(Clone, Copy, Debug)] #[derive(Clone, Copy, Debug)]
pub struct ConnectInfo<T>(pub T); pub struct ConnectInfo<T>(pub T);
#[async_trait]
impl<S, T> FromRequestParts<S> for ConnectInfo<T> impl<S, T> FromRequestParts<S> for ConnectInfo<T>
where where
S: Send + Sync, S: Send + Sync,

View file

@ -2,7 +2,6 @@ use super::{
rejection::{FailedToResolveHost, HostRejection}, rejection::{FailedToResolveHost, HostRejection},
FromRequestParts, FromRequestParts,
}; };
use async_trait::async_trait;
use http::{ use http::{
header::{HeaderMap, FORWARDED}, header::{HeaderMap, FORWARDED},
request::Parts, request::Parts,
@ -23,7 +22,6 @@ const X_FORWARDED_HOST_HEADER_KEY: &str = "X-Forwarded-Host";
#[derive(Debug, Clone)] #[derive(Debug, Clone)]
pub struct Host(pub String); pub struct Host(pub String);
#[async_trait]
impl<S> FromRequestParts<S> for Host impl<S> FromRequestParts<S> for Host
where where
S: Send + Sync, S: Send + Sync,

View file

@ -1,6 +1,5 @@
use super::{rejection::*, FromRequestParts}; use super::{rejection::*, FromRequestParts};
use crate::routing::{RouteId, NEST_TAIL_PARAM_CAPTURE}; use crate::routing::{RouteId, NEST_TAIL_PARAM_CAPTURE};
use async_trait::async_trait;
use http::request::Parts; use http::request::Parts;
use std::{collections::HashMap, sync::Arc}; use std::{collections::HashMap, sync::Arc};
@ -63,7 +62,6 @@ impl MatchedPath {
} }
} }
#[async_trait]
impl<S> FromRequestParts<S> for MatchedPath impl<S> FromRequestParts<S> for MatchedPath
where where
S: Send + Sync, S: Send + Sync,

View file

@ -4,7 +4,6 @@
use super::{FromRequest, Request}; use super::{FromRequest, Request};
use crate::body::Bytes; use crate::body::Bytes;
use async_trait::async_trait;
use axum_core::{ use axum_core::{
__composite_rejection as composite_rejection, __define_rejection as define_rejection, __composite_rejection as composite_rejection, __define_rejection as define_rejection,
response::{IntoResponse, Response}, response::{IntoResponse, Response},
@ -65,7 +64,6 @@ pub struct Multipart {
inner: multer::Multipart<'static>, inner: multer::Multipart<'static>,
} }
#[async_trait]
impl<S> FromRequest<S> for Multipart impl<S> FromRequest<S> for Multipart
where where
S: Send + Sync, S: Send + Sync,

View file

@ -4,7 +4,6 @@ use std::{
}; };
use crate::extract::Request; use crate::extract::Request;
use async_trait::async_trait;
use axum_core::extract::FromRequestParts; use axum_core::extract::FromRequestParts;
use http::request::Parts; use http::request::Parts;
use tower_layer::{layer_fn, Layer}; use tower_layer::{layer_fn, Layer};
@ -47,7 +46,6 @@ impl NestedPath {
} }
} }
#[async_trait]
impl<S> FromRequestParts<S> for NestedPath impl<S> FromRequestParts<S> for NestedPath
where where
S: Send + Sync, S: Send + Sync,

View file

@ -8,7 +8,6 @@ use crate::{
routing::url_params::UrlParams, routing::url_params::UrlParams,
util::PercentDecodedStr, util::PercentDecodedStr,
}; };
use async_trait::async_trait;
use axum_core::response::{IntoResponse, Response}; use axum_core::response::{IntoResponse, Response};
use http::{request::Parts, StatusCode}; use http::{request::Parts, StatusCode};
use serde::de::DeserializeOwned; use serde::de::DeserializeOwned;
@ -145,7 +144,6 @@ pub struct Path<T>(pub T);
axum_core::__impl_deref!(Path); axum_core::__impl_deref!(Path);
#[async_trait]
impl<T, S> FromRequestParts<S> for Path<T> impl<T, S> FromRequestParts<S> for Path<T>
where where
T: DeserializeOwned + Send, T: DeserializeOwned + Send,
@ -445,7 +443,6 @@ impl std::error::Error for FailedToDeserializePathParams {}
#[derive(Debug)] #[derive(Debug)]
pub struct RawPathParams(Vec<(Arc<str>, PercentDecodedStr)>); pub struct RawPathParams(Vec<(Arc<str>, PercentDecodedStr)>);
#[async_trait]
impl<S> FromRequestParts<S> for RawPathParams impl<S> FromRequestParts<S> for RawPathParams
where where
S: Send + Sync, S: Send + Sync,

View file

@ -1,5 +1,4 @@
use super::{rejection::*, FromRequestParts}; use super::{rejection::*, FromRequestParts};
use async_trait::async_trait;
use http::{request::Parts, Uri}; use http::{request::Parts, Uri};
use serde::de::DeserializeOwned; use serde::de::DeserializeOwned;
@ -46,7 +45,6 @@ use serde::de::DeserializeOwned;
#[derive(Debug, Clone, Copy, Default)] #[derive(Debug, Clone, Copy, Default)]
pub struct Query<T>(pub T); pub struct Query<T>(pub T);
#[async_trait]
impl<T, S> FromRequestParts<S> for Query<T> impl<T, S> FromRequestParts<S> for Query<T>
where where
T: DeserializeOwned, T: DeserializeOwned,

View file

@ -1,4 +1,3 @@
use async_trait::async_trait;
use axum_core::extract::{FromRequest, Request}; use axum_core::extract::{FromRequest, Request};
use bytes::Bytes; use bytes::Bytes;
use http::Method; use http::Method;
@ -30,7 +29,6 @@ use super::{
#[derive(Debug)] #[derive(Debug)]
pub struct RawForm(pub Bytes); pub struct RawForm(pub Bytes);
#[async_trait]
impl<S> FromRequest<S> for RawForm impl<S> FromRequest<S> for RawForm
where where
S: Send + Sync, S: Send + Sync,

View file

@ -1,5 +1,4 @@
use super::FromRequestParts; use super::FromRequestParts;
use async_trait::async_trait;
use http::request::Parts; use http::request::Parts;
use std::convert::Infallible; use std::convert::Infallible;
@ -25,7 +24,6 @@ use std::convert::Infallible;
#[derive(Debug)] #[derive(Debug)]
pub struct RawQuery(pub Option<String>); pub struct RawQuery(pub Option<String>);
#[async_trait]
impl<S> FromRequestParts<S> for RawQuery impl<S> FromRequestParts<S> for RawQuery
where where
S: Send + Sync, S: Send + Sync,

View file

@ -1,5 +1,4 @@
use super::{Extension, FromRequestParts}; use super::{Extension, FromRequestParts};
use async_trait::async_trait;
use http::{request::Parts, Uri}; use http::{request::Parts, Uri};
use std::convert::Infallible; use std::convert::Infallible;
@ -70,7 +69,6 @@ use std::convert::Infallible;
pub struct OriginalUri(pub Uri); pub struct OriginalUri(pub Uri);
#[cfg(feature = "original-uri")] #[cfg(feature = "original-uri")]
#[async_trait]
impl<S> FromRequestParts<S> for OriginalUri impl<S> FromRequestParts<S> for OriginalUri
where where
S: Send + Sync, S: Send + Sync,

View file

@ -1,4 +1,3 @@
use async_trait::async_trait;
use axum_core::extract::{FromRef, FromRequestParts}; use axum_core::extract::{FromRef, FromRequestParts};
use http::request::Parts; use http::request::Parts;
use std::{ use std::{
@ -219,13 +218,11 @@ use std::{
/// ```rust /// ```rust
/// use axum_core::extract::{FromRequestParts, FromRef}; /// use axum_core::extract::{FromRequestParts, FromRef};
/// use http::request::Parts; /// use http::request::Parts;
/// use async_trait::async_trait;
/// use std::convert::Infallible; /// use std::convert::Infallible;
/// ///
/// // the extractor your library provides /// // the extractor your library provides
/// struct MyLibraryExtractor; /// struct MyLibraryExtractor;
/// ///
/// #[async_trait]
/// impl<S> FromRequestParts<S> for MyLibraryExtractor /// impl<S> FromRequestParts<S> for MyLibraryExtractor
/// where /// where
/// // keep `S` generic but require that it can produce a `MyLibraryState` /// // keep `S` generic but require that it can produce a `MyLibraryState`
@ -344,7 +341,6 @@ use std::{
#[derive(Debug, Default, Clone, Copy)] #[derive(Debug, Default, Clone, Copy)]
pub struct State<S>(pub S); pub struct State<S>(pub S);
#[async_trait]
impl<OuterState, InnerState> FromRequestParts<OuterState> for State<InnerState> impl<OuterState, InnerState> FromRequestParts<OuterState> for State<InnerState>
where where
InnerState: FromRef<OuterState>, InnerState: FromRef<OuterState>,

View file

@ -93,7 +93,6 @@
use self::rejection::*; use self::rejection::*;
use super::FromRequestParts; use super::FromRequestParts;
use crate::{body::Bytes, response::Response, Error}; use crate::{body::Bytes, response::Response, Error};
use async_trait::async_trait;
use axum_core::body::Body; use axum_core::body::Body;
use futures_util::{ use futures_util::{
sink::{Sink, SinkExt}, sink::{Sink, SinkExt},
@ -381,7 +380,6 @@ impl OnFailedUpgrade for DefaultOnFailedUpgrade {
fn call(self, _error: Error) {} fn call(self, _error: Error) {}
} }
#[async_trait]
impl<S> FromRequestParts<S> for WebSocketUpgrade<DefaultOnFailedUpgrade> impl<S> FromRequestParts<S> for WebSocketUpgrade<DefaultOnFailedUpgrade>
where where
S: Send + Sync, S: Send + Sync,

View file

@ -1,6 +1,5 @@
use crate::extract::Request; use crate::extract::Request;
use crate::extract::{rejection::*, FromRequest, RawForm}; use crate::extract::{rejection::*, FromRequest, RawForm};
use async_trait::async_trait;
use axum_core::response::{IntoResponse, Response}; use axum_core::response::{IntoResponse, Response};
use axum_core::RequestExt; use axum_core::RequestExt;
use http::header::CONTENT_TYPE; use http::header::CONTENT_TYPE;
@ -72,7 +71,6 @@ use serde::Serialize;
#[must_use] #[must_use]
pub struct Form<T>(pub T); pub struct Form<T>(pub T);
#[async_trait]
impl<T, S> FromRequest<S> for Form<T> impl<T, S> FromRequest<S> for Form<T>
where where
T: DeserializeOwned, T: DeserializeOwned,

View file

@ -1,6 +1,5 @@
use crate::extract::Request; use crate::extract::Request;
use crate::extract::{rejection::*, FromRequest}; use crate::extract::{rejection::*, FromRequest};
use async_trait::async_trait;
use axum_core::response::{IntoResponse, Response}; use axum_core::response::{IntoResponse, Response};
use bytes::{BufMut, Bytes, BytesMut}; use bytes::{BufMut, Bytes, BytesMut};
use http::{ use http::{
@ -92,7 +91,6 @@ use serde::{de::DeserializeOwned, Serialize};
#[must_use] #[must_use]
pub struct Json<T>(pub T); pub struct Json<T>(pub T);
#[async_trait]
impl<T, S> FromRequest<S> for Json<T> impl<T, S> FromRequest<S> for Json<T>
where where
T: DeserializeOwned, T: DeserializeOwned,

View file

@ -443,8 +443,6 @@ pub mod serve;
#[cfg(test)] #[cfg(test)]
mod test_helpers; mod test_helpers;
#[doc(no_inline)]
pub use async_trait::async_trait;
#[doc(no_inline)] #[doc(no_inline)]
pub use http; pub use http;

View file

@ -39,12 +39,10 @@ use tower_service::Service;
/// Router, /// Router,
/// http::{header, StatusCode, request::Parts}, /// http::{header, StatusCode, request::Parts},
/// }; /// };
/// use async_trait::async_trait;
/// ///
/// // An extractor that performs authorization. /// // An extractor that performs authorization.
/// struct RequireAuth; /// struct RequireAuth;
/// ///
/// #[async_trait]
/// impl<S> FromRequestParts<S> for RequireAuth /// impl<S> FromRequestParts<S> for RequireAuth
/// where /// where
/// S: Send + Sync, /// S: Send + Sync,
@ -303,7 +301,7 @@ where
#[cfg(test)] #[cfg(test)]
mod tests { mod tests {
use super::*; 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 axum_core::extract::FromRef;
use http::{header, request::Parts, StatusCode}; use http::{header, request::Parts, StatusCode};
use tower_http::limit::RequestBodyLimitLayer; use tower_http::limit::RequestBodyLimitLayer;
@ -315,7 +313,6 @@ mod tests {
struct RequireAuth; struct RequireAuth;
#[async_trait::async_trait]
impl<S> FromRequestParts<S> for RequireAuth impl<S> FromRequestParts<S> for RequireAuth
where where
S: Send + Sync, S: Send + Sync,
@ -368,7 +365,6 @@ mod tests {
fn works_with_request_body_limit() { fn works_with_request_body_limit() {
struct MyExtractor; struct MyExtractor;
#[async_trait]
impl<S> FromRequestParts<S> for MyExtractor impl<S> FromRequestParts<S> for MyExtractor
where where
S: Send + Sync, S: Send + Sync,

View file

@ -5,7 +5,6 @@
//! ``` //! ```
use axum::{ use axum::{
async_trait,
body::{Body, Bytes}, body::{Body, Bytes},
extract::{FromRequest, Request}, extract::{FromRequest, Request},
http::StatusCode, http::StatusCode,
@ -74,7 +73,6 @@ async fn handler(BufferRequestBody(body): BufferRequestBody) {
struct BufferRequestBody(Bytes); struct BufferRequestBody(Bytes);
// we must implement `FromRequest` (and not `FromRequestParts`) to consume the body // we must implement `FromRequest` (and not `FromRequestParts`) to consume the body
#[async_trait]
impl<S> FromRequest<S> for BufferRequestBody impl<S> FromRequest<S> for BufferRequestBody
where where
S: Send + Sync, S: Send + Sync,

View file

@ -5,7 +5,6 @@
//! - Boilerplate: Requires creating a new extractor for every custom rejection //! - Boilerplate: Requires creating a new extractor for every custom rejection
//! - Complexity: Manually implementing `FromRequest` results on more complex code //! - Complexity: Manually implementing `FromRequest` results on more complex code
use axum::{ use axum::{
async_trait,
extract::{rejection::JsonRejection, FromRequest, MatchedPath, Request}, extract::{rejection::JsonRejection, FromRequest, MatchedPath, Request},
http::StatusCode, http::StatusCode,
response::IntoResponse, response::IntoResponse,
@ -20,7 +19,6 @@ pub async fn handler(Json(value): Json<Value>) -> impl IntoResponse {
// We define our own `Json` extractor that customizes the error from `axum::Json` // We define our own `Json` extractor that customizes the error from `axum::Json`
pub struct Json<T>(pub T); pub struct Json<T>(pub T);
#[async_trait]
impl<S, T> FromRequest<S> for Json<T> impl<S, T> FromRequest<S> for Json<T>
where where
axum::Json<T>: FromRequest<S, Rejection = JsonRejection>, axum::Json<T>: FromRequest<S, Rejection = JsonRejection>,

View file

@ -5,7 +5,6 @@
//! ``` //! ```
use axum::{ use axum::{
async_trait,
extract::{path::ErrorKind, rejection::PathRejection, FromRequestParts}, extract::{path::ErrorKind, rejection::PathRejection, FromRequestParts},
http::{request::Parts, StatusCode}, http::{request::Parts, StatusCode},
response::IntoResponse, response::IntoResponse,
@ -49,7 +48,6 @@ struct Params {
// We define our own `Path` extractor that customizes the error from `axum::extract::Path` // We define our own `Path` extractor that customizes the error from `axum::extract::Path`
struct Path<T>(T); struct Path<T>(T);
#[async_trait]
impl<S, T> FromRequestParts<S> for Path<T> impl<S, T> FromRequestParts<S> for Path<T>
where where
// these trait bounds are copied from `impl FromRequest for axum::extract::path::Path` // these trait bounds are copied from `impl FromRequest for axum::extract::path::Path`

View file

@ -13,7 +13,6 @@
//! for a real world application using axum and diesel //! for a real world application using axum and diesel
use axum::{ use axum::{
async_trait,
extract::{FromRef, FromRequestParts, State}, extract::{FromRef, FromRequestParts, State},
http::{request::Parts, StatusCode}, http::{request::Parts, StatusCode},
response::Json, response::Json,
@ -102,7 +101,6 @@ struct DatabaseConnection(
bb8::PooledConnection<'static, AsyncDieselConnectionManager<AsyncPgConnection>>, bb8::PooledConnection<'static, AsyncDieselConnectionManager<AsyncPgConnection>>,
); );
#[async_trait]
impl<S> FromRequestParts<S> for DatabaseConnection impl<S> FromRequestParts<S> for DatabaseConnection
where where
S: Send + Sync, S: Send + Sync,

View file

@ -7,7 +7,6 @@
//! ``` //! ```
use axum::{ use axum::{
async_trait,
extract::FromRequestParts, extract::FromRequestParts,
http::{request::Parts, StatusCode}, http::{request::Parts, StatusCode},
response::{IntoResponse, Response}, response::{IntoResponse, Response},
@ -122,7 +121,6 @@ impl AuthBody {
} }
} }
#[async_trait]
impl<S> FromRequestParts<S> for Claims impl<S> FromRequestParts<S> for Claims
where where
S: Send + Sync, S: Send + Sync,

View file

@ -11,7 +11,6 @@
use anyhow::{Context, Result}; use anyhow::{Context, Result};
use async_session::{MemoryStore, Session, SessionStore}; use async_session::{MemoryStore, Session, SessionStore};
use axum::{ use axum::{
async_trait,
extract::{FromRef, FromRequestParts, Query, State}, extract::{FromRef, FromRequestParts, Query, State},
http::{header::SET_COOKIE, HeaderMap}, http::{header::SET_COOKIE, HeaderMap},
response::{IntoResponse, Redirect, Response}, response::{IntoResponse, Redirect, Response},
@ -249,7 +248,6 @@ impl IntoResponse for AuthRedirect {
} }
} }
#[async_trait]
impl<S> FromRequestParts<S> for User impl<S> FromRequestParts<S> for User
where where
MemoryStore: FromRef<S>, MemoryStore: FromRef<S>,

View file

@ -7,7 +7,6 @@
//! ``` //! ```
use axum::{ use axum::{
async_trait,
extract::{FromRequest, Request}, extract::{FromRequest, Request},
http::{header::CONTENT_TYPE, StatusCode}, http::{header::CONTENT_TYPE, StatusCode},
response::{IntoResponse, Response}, response::{IntoResponse, Response},
@ -48,7 +47,6 @@ async fn handler(JsonOrForm(payload): JsonOrForm<Payload>) {
struct JsonOrForm<T>(T); struct JsonOrForm<T>(T);
#[async_trait]
impl<S, T> FromRequest<S> for JsonOrForm<T> impl<S, T> FromRequest<S> for JsonOrForm<T>
where where
S: Send + Sync, S: Send + Sync,

View file

@ -14,7 +14,6 @@
//! ``` //! ```
use axum::{ use axum::{
async_trait,
extract::{FromRef, FromRequestParts, State}, extract::{FromRef, FromRequestParts, State},
http::{request::Parts, StatusCode}, http::{request::Parts, StatusCode},
routing::get, routing::get,
@ -75,7 +74,6 @@ async fn using_connection_pool_extractor(
// which setup is appropriate depends on your application // which setup is appropriate depends on your application
struct DatabaseConnection(sqlx::pool::PoolConnection<sqlx::Postgres>); struct DatabaseConnection(sqlx::pool::PoolConnection<sqlx::Postgres>);
#[async_trait]
impl<S> FromRequestParts<S> for DatabaseConnection impl<S> FromRequestParts<S> for DatabaseConnection
where where
PgPool: FromRef<S>, PgPool: FromRef<S>,

View file

@ -5,7 +5,6 @@
//! ``` //! ```
use axum::{ use axum::{
async_trait,
extract::{FromRef, FromRequestParts, State}, extract::{FromRef, FromRequestParts, State},
http::{request::Parts, StatusCode}, http::{request::Parts, StatusCode},
routing::get, routing::get,
@ -68,7 +67,6 @@ async fn using_connection_pool_extractor(
// which setup is appropriate depends on your application // which setup is appropriate depends on your application
struct DatabaseConnection(PooledConnection<'static, PostgresConnectionManager<NoTls>>); struct DatabaseConnection(PooledConnection<'static, PostgresConnectionManager<NoTls>>);
#[async_trait]
impl<S> FromRequestParts<S> for DatabaseConnection impl<S> FromRequestParts<S> for DatabaseConnection
where where
ConnectionPool: FromRef<S>, ConnectionPool: FromRef<S>,

View file

@ -5,7 +5,6 @@ publish = false
version = "0.1.0" version = "0.1.0"
[dependencies] [dependencies]
async-trait = "0.1.67"
axum = { path = "../../axum" } axum = { path = "../../axum" }
http-body = "1.0.0" http-body = "1.0.0"
serde = { version = "1.0", features = ["derive"] } serde = { version = "1.0", features = ["derive"] }

View file

@ -10,7 +10,6 @@
//! -> <h1>Hello, LT!</h1> //! -> <h1>Hello, LT!</h1>
//! ``` //! ```
use async_trait::async_trait;
use axum::{ use axum::{
extract::{rejection::FormRejection, Form, FromRequest, Request}, extract::{rejection::FormRejection, Form, FromRequest, Request},
http::StatusCode, http::StatusCode,
@ -56,7 +55,6 @@ async fn handler(ValidatedForm(input): ValidatedForm<NameInput>) -> Html<String>
#[derive(Debug, Clone, Copy, Default)] #[derive(Debug, Clone, Copy, Default)]
pub struct ValidatedForm<T>(pub T); pub struct ValidatedForm<T>(pub T);
#[async_trait]
impl<T, S> FromRequest<S> for ValidatedForm<T> impl<T, S> FromRequest<S> for ValidatedForm<T>
where where
T: DeserializeOwned + Validate, T: DeserializeOwned + Validate,

View file

@ -5,7 +5,6 @@
//! ``` //! ```
use axum::{ use axum::{
async_trait,
extract::{FromRequestParts, Path}, extract::{FromRequestParts, Path},
http::{request::Parts, StatusCode}, http::{request::Parts, StatusCode},
response::{IntoResponse, Response}, response::{IntoResponse, Response},
@ -47,7 +46,6 @@ enum Version {
V3, V3,
} }
#[async_trait]
impl<S> FromRequestParts<S> for Version impl<S> FromRequestParts<S> for Version
where where
S: Send + Sync, S: Send + Sync,