Replace async_trait with AFIT / RPITIT (#2308)

Co-authored-by: Jonas Platte <jplatte+git@posteo.de>
This commit is contained in:
Zheng Li 2024-09-29 05:27:11 +08:00 committed by GitHub
parent dda5a273b5
commit 19101f624d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
69 changed files with 116 additions and 267 deletions

View file

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

View file

@ -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<S>(pub(crate) S);
#[async_trait]
impl<OuterState, InnerState> FromRequestParts<OuterState> for State<InnerState>
where
InnerState: FromRef<OuterState>,
@ -33,7 +31,6 @@ mod tests {
#[allow(dead_code)]
pub(crate) struct RequiresState(pub(crate) String);
#[async_trait]
impl<S> FromRequestParts<S> for RequiresState
where
S: Send + Sync,

View file

@ -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>(T);
///
/// #[async_trait]
/// impl<S, T> FromRequest<S> for FormOrJson<T>
/// where
/// 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
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<S> FromRequest<S> for MyExtractor
/// where
/// String: FromRef<S>,
@ -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<S> FromRequest<S> for RequiresState
/// where
/// 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
E: FromRequest<S, M> + '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<S, T> FromRequest<S> for MyExtractor<T>
/// where
/// 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
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<S, T> FromRequest<S> for MyExtractor<T>
/// where
/// String: FromRef<S>,
@ -234,7 +228,6 @@ pub trait RequestExt: sealed::Sealed + Sized {
///
/// struct RequiresState {}
///
/// #[async_trait]
/// impl<S> FromRequestParts<S> for RequiresState
/// where
/// String: FromRef<S>,
@ -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<E, E::Rejection>>
) -> impl Future<Output = Result<E, E::Rejection>> + Send + 'a
where
E: FromRequestParts<S> + 'static,
S: Send + Sync;
@ -267,7 +260,7 @@ pub trait RequestExt: sealed::Sealed + Sized {
}
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
E: FromRequest<(), M> + 'static,
M: 'static,
@ -275,7 +268,10 @@ impl RequestExt for Request {
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
E: FromRequest<S, M> + 'static,
S: Send + Sync,
@ -283,17 +279,17 @@ impl RequestExt for Request {
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
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<E, E::Rejection>>
) -> Result<E, E::Rejection>
where
E: FromRequestParts<S> + '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<S> FromRequest<S> for WorksForCustomExtractor
where
S: Send + Sync,

View file

@ -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<String, String>,
/// }
///
/// #[async_trait]
/// impl<S> FromRequestParts<S> for MyExtractor
/// where
/// 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
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<S> FromRequestParts<S> for MyExtractor
/// where
/// String: FromRef<S>,
@ -97,7 +93,6 @@ pub trait RequestPartsExt: sealed::Sealed + Sized {
/// struct RequiresState { /* ... */ }
///
/// // some extractor that requires a `String` in the state
/// #[async_trait]
/// impl<S> FromRequestParts<S> for RequiresState
/// where
/// String: FromRef<S>,
@ -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<E, E::Rejection>>
) -> impl Future<Output = Result<E, E::Rejection>> + Send + 'a
where
E: FromRequestParts<S> + 'static,
S: Send + Sync;
}
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
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<E, E::Rejection>>
) -> impl Future<Output = Result<E, E::Rejection>> + Send + 'a
where
E: FromRequestParts<S> + '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<S> FromRequestParts<S> for WorksForCustomExtractor
where
S: Send + Sync,

View file

@ -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]
#[rustversion::attr(
since(1.78),
diagnostic::on_unimplemented(
@ -55,7 +54,10 @@ pub trait FromRequestParts<S>: Sized {
type Rejection: IntoResponse;
/// 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.
@ -69,7 +71,6 @@ pub trait FromRequestParts<S>: Sized {
/// See [`axum::extract`] for more general docs about extractors.
///
/// [`axum::extract`]: https://docs.rs/axum/0.7/axum/extract/index.html
#[async_trait]
#[rustversion::attr(
since(1.78),
diagnostic::on_unimplemented(
@ -82,10 +83,12 @@ pub trait FromRequest<S, M = private::ViaRequest>: Sized {
type Rejection: IntoResponse;
/// 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
where
S: Send + Sync,
@ -99,7 +102,6 @@ where
}
}
#[async_trait]
impl<S, T> FromRequestParts<S> for Option<T>
where
T: FromRequestParts<S>,
@ -115,7 +117,6 @@ where
}
}
#[async_trait]
impl<S, T> FromRequest<S> for Option<T>
where
T: FromRequest<S>,
@ -128,7 +129,6 @@ where
}
}
#[async_trait]
impl<S, T> FromRequestParts<S> for Result<T, T::Rejection>
where
T: FromRequestParts<S>,
@ -141,7 +141,6 @@ where
}
}
#[async_trait]
impl<S, T> FromRequest<S> for Result<T, T::Rejection>
where
T: FromRequest<S>,

View file

@ -1,12 +1,10 @@
use super::{rejection::*, FromRequest, FromRequestParts, Request};
use crate::{body::Body, RequestExt};
use async_trait::async_trait;
use bytes::{BufMut, Bytes, BytesMut};
use http::{request::Parts, Extensions, HeaderMap, Method, Uri, Version};
use http_body_util::BodyExt;
use std::convert::Infallible;
#[async_trait]
impl<S> FromRequest<S> for Request
where
S: Send + Sync,
@ -18,7 +16,6 @@ where
}
}
#[async_trait]
impl<S> FromRequestParts<S> for Method
where
S: Send + Sync,
@ -30,7 +27,6 @@ where
}
}
#[async_trait]
impl<S> FromRequestParts<S> for Uri
where
S: Send + Sync,
@ -42,7 +38,6 @@ where
}
}
#[async_trait]
impl<S> FromRequestParts<S> 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<S> FromRequestParts<S> for HeaderMap
where
S: Send + Sync,
@ -71,7 +65,6 @@ where
}
}
#[async_trait]
impl<S> FromRequest<S> for BytesMut
where
S: Send + Sync,
@ -102,7 +95,6 @@ async fn body_to_bytes_mut(body: &mut Body, bytes: &mut BytesMut) -> Result<(),
Ok(())
}
#[async_trait]
impl<S> FromRequest<S> for Bytes
where
S: Send + Sync,
@ -121,7 +113,6 @@ where
}
}
#[async_trait]
impl<S> FromRequest<S> for String
where
S: Send + Sync,
@ -143,7 +134,6 @@ where
}
}
#[async_trait]
impl<S> FromRequestParts<S> for Parts
where
S: Send + Sync,
@ -155,7 +145,6 @@ where
}
}
#[async_trait]
impl<S> FromRequestParts<S> for Extensions
where
S: Send + Sync,
@ -167,7 +156,6 @@ where
}
}
#[async_trait]
impl<S> FromRequest<S> for Body
where
S: Send + Sync,

View file

@ -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<S> FromRequestParts<S> 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<S, $($ty,)* $last> FromRequestParts<S> 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<S, Mut>` for `T: FromRequestParts<S>`.
#[async_trait]
#[allow(non_snake_case, unused_mut, unused_variables)]
impl<S, $($ty,)* $last> FromRequest<S> for ($($ty,)* $last,)
where

View file

@ -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<S> FromRequestParts<S> for AdminPermissions
//! where
//! S: Send + Sync,
@ -29,7 +27,6 @@
//!
//! struct User {}
//!
//! #[async_trait]
//! impl<S> FromRequestParts<S> 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<S, $($ident),*, $last> FromRequestParts<S> for $either<$($ident),*, $last>
where
$($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> {
$(
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));
}
)*
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::{
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<S> FromRequestParts<S> for Session
/// where
/// S: Send + Sync,
@ -43,7 +38,6 @@ use http::request::Parts;
///
/// struct CurrentUser { /* ... */ }
///
/// #[async_trait]
/// impl<S> FromRequestParts<S> for CurrentUser
/// where
/// S: Send + Sync,
@ -86,7 +80,6 @@ pub struct Cached<T>(pub T);
#[derive(Clone)]
struct CachedEntry<T>(T);
#[async_trait]
impl<S, T> FromRequestParts<S> for Cached<T>
where
S: Send + Sync,
@ -125,7 +118,6 @@ mod tests {
#[derive(Clone, Debug, PartialEq, Eq)]
struct Extractor(Instant);
#[async_trait]
impl<S> FromRequestParts<S> for Extractor
where
S: Send + Sync,

View file

@ -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<S> FromRequestParts<S> for CookieJar
where
S: Send + Sync,

View file

@ -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<K> fmt::Debug for PrivateCookieJar<K> {
}
}
#[async_trait]
impl<S, K> FromRequestParts<S> for PrivateCookieJar<K>
where
S: Send + Sync,

View file

@ -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<K> fmt::Debug for SignedCookieJar<K> {
}
}
#[async_trait]
impl<S, K> FromRequestParts<S> for SignedCookieJar<K>
where
S: Send + Sync,

View file

@ -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<T>(pub T);
axum_core::__impl_deref!(Form);
#[async_trait]
impl<T, S> FromRequest<S> for Form<T>
where
T: DeserializeOwned,

View file

@ -1,4 +1,3 @@
use axum::async_trait;
use axum::extract::{FromRequest, Request};
use axum_core::__composite_rejection as composite_rejection;
use axum_core::__define_rejection as define_rejection;
@ -84,7 +83,6 @@ pub struct JsonDeserializer<T> {
_marker: PhantomData<T>,
}
#[async_trait]
impl<T, S> FromRequest<S> for JsonDeserializer<T>
where
T: Deserialize<'static>,

View file

@ -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<S> FromRequest<S> for Multipart
where
S: Send + Sync,

View file

@ -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<T>(pub Option<T>);
#[async_trait]
impl<T, S> FromRequestParts<S> for OptionalPath<T>
where
T: DeserializeOwned + Send + 'static,

View file

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

View file

@ -1,4 +1,3 @@
use axum::async_trait;
use axum::extract::{FromRequest, FromRequestParts, Request};
use axum::response::IntoResponse;
use http::request::Parts;
@ -110,7 +109,6 @@ impl<E, R> DerefMut for WithRejection<E, R> {
}
}
#[async_trait]
impl<E, R, S> FromRequest<S> for WithRejection<E, R>
where
S: Send + Sync,
@ -125,7 +123,6 @@ where
}
}
#[async_trait]
impl<E, R, S> FromRequestParts<S> for WithRejection<E, R>
where
S: Send + Sync,
@ -169,7 +166,6 @@ mod tests {
struct TestExtractor;
struct TestRejection;
#[async_trait]
impl<S> FromRequestParts<S> for TestExtractor
where
S: Send + Sync,

View file

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

View file

@ -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<S> JsonLines<S, AsResponse> {
}
}
#[async_trait]
impl<S, T> FromRequest<S> for JsonLines<T, AsExtractor>
where
T: DeserializeOwned,

View file

@ -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<T>(pub T);
#[async_trait]
impl<T, S> FromRequest<S> for Protobuf<T>
where
T: Message + Default,

View file

@ -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<T>(pub T);
#[async_trait]
impl<T, S> FromRequestParts<S> for TypedHeader<T>
where
T: Header,

View file

@ -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
@ -435,7 +433,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 {
let span = path.span();
quote_spanned! {span=>
@ -448,6 +446,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 last = match tr {
@ -464,16 +479,17 @@ fn extract_fields(
let member = member(field, index);
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() {
let field_ty = into_outer(&via, ty_span, peel_option(&field.ty).unwrap());
let tokens = match tr {
Trait::FromRequest => {
quote_spanned! {ty_span=>
#member: {
let (mut parts, body) = req.into_parts();
let value =
::axum::extract::FromRequestParts::from_request_parts(
<#field_ty as ::axum::extract::FromRequestParts<_>>::from_request_parts(
&mut parts,
state,
)
@ -488,7 +504,7 @@ fn extract_fields(
Trait::FromRequestParts => {
quote_spanned! {ty_span=>
#member: {
::axum::extract::FromRequestParts::from_request_parts(
<#field_ty as ::axum::extract::FromRequestParts<_>>::from_request_parts(
parts,
state,
)
@ -501,13 +517,14 @@ fn extract_fields(
};
Ok(tokens)
} 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 {
Trait::FromRequest => {
quote_spanned! {ty_span=>
#member: {
let (mut parts, body) = req.into_parts();
let value =
::axum::extract::FromRequestParts::from_request_parts(
<#field_ty as ::axum::extract::FromRequestParts<_>>::from_request_parts(
&mut parts,
state,
)
@ -521,7 +538,7 @@ fn extract_fields(
Trait::FromRequestParts => {
quote_spanned! {ty_span=>
#member: {
::axum::extract::FromRequestParts::from_request_parts(
<#field_ty as ::axum::extract::FromRequestParts<_>>::from_request_parts(
parts,
state,
)
@ -533,6 +550,7 @@ fn extract_fields(
};
Ok(tokens)
} else {
let field_ty = into_outer(&via,ty_span,&field.ty);
let map_err = if let Some(rejection) = rejection {
quote! { <#rejection as ::std::convert::From<_>>::from }
} else {
@ -545,7 +563,7 @@ fn extract_fields(
#member: {
let (mut parts, body) = req.into_parts();
let value =
::axum::extract::FromRequestParts::from_request_parts(
<#field_ty as ::axum::extract::FromRequestParts<_>>::from_request_parts(
&mut parts,
state,
)
@ -560,7 +578,7 @@ fn extract_fields(
Trait::FromRequestParts => {
quote_spanned! {ty_span=>
#member: {
::axum::extract::FromRequestParts::from_request_parts(
<#field_ty as ::axum::extract::FromRequestParts<_>>::from_request_parts(
parts,
state,
)
@ -582,26 +600,29 @@ fn extract_fields(
let member = member(field, fields.len() - 1);
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 field_ty = into_outer(&via, ty_span, peel_option(&field.ty).unwrap());
quote_spanned! {ty_span=>
#member: {
::axum::extract::FromRequest::from_request(req, state)
<#field_ty as ::axum::extract::FromRequest<_, _>>::from_request(req, state)
.await
.ok()
.map(#into_inner)
},
}
} 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=>
#member: {
::axum::extract::FromRequest::from_request(req, state)
<#field_ty as ::axum::extract::FromRequest<_, _>>::from_request(req, state)
.await
.map(#into_inner)
},
}
} else {
let field_ty = into_outer(&via, ty_span, &field.ty);
let map_err = if let Some(rejection) = rejection {
quote! { <#rejection as ::std::convert::From<_>>::from }
} else {
@ -610,7 +631,7 @@ fn extract_fields(
quote_spanned! {ty_span=>
#member: {
::axum::extract::FromRequest::from_request(req, state)
<#field_ty as ::axum::extract::FromRequest<_, _>>::from_request(req, state)
.await
.map(#into_inner)
.map_err(#map_err)?
@ -807,7 +828,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
@ -821,7 +841,7 @@ fn impl_struct_by_extracting_all_at_once(
req: ::axum::http::Request<::axum::body::Body>,
state: &#state,
) -> ::std::result::Result<Self, Self::Rejection> {
::axum::extract::FromRequest::from_request(req, state)
<#via_path<#via_type_generics> as ::axum::extract::FromRequest<_, _>>::from_request(req, state)
.await
.map(|#via_path(value)| #value_to_self)
.map_err(#map_err)
@ -831,7 +851,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
@ -845,7 +864,7 @@ fn impl_struct_by_extracting_all_at_once(
parts: &mut ::axum::http::request::Parts,
state: &#state,
) -> ::std::result::Result<Self, Self::Rejection> {
::axum::extract::FromRequestParts::from_request_parts(parts, state)
<#via_path<#via_type_generics> as ::axum::extract::FromRequestParts<_>>::from_request_parts(parts, state)
.await
.map(|#via_path(value)| #value_to_self)
.map_err(#map_err)
@ -920,7 +939,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
@ -932,7 +950,7 @@ fn impl_enum_by_extracting_all_at_once(
req: ::axum::http::Request<::axum::body::Body>,
state: &#state,
) -> ::std::result::Result<Self, Self::Rejection> {
::axum::extract::FromRequest::from_request(req, state)
<#path::<#ident> as ::axum::extract::FromRequest<_, _>>::from_request(req, state)
.await
.map(|#path(inner)| inner)
.map_err(#map_err)
@ -942,7 +960,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
@ -954,7 +971,7 @@ fn impl_enum_by_extracting_all_at_once(
parts: &mut ::axum::http::request::Parts,
state: &#state,
) -> ::std::result::Result<Self, Self::Rejection> {
::axum::extract::FromRequestParts::from_request_parts(parts, state)
<#path::<#ident> as ::axum::extract::FromRequestParts<_>>::from_request_parts(parts, state)
.await
.map(|#path(inner)| inner)
.map_err(#map_err)

View file

@ -246,7 +246,6 @@ use from_request::Trait::{FromRequest, FromRequestParts};
///
/// struct MyInnerType;
///
/// #[axum::async_trait]
/// impl FromRequestParts<CustomState> for MyInnerType {
/// // ...
/// # type Rejection = ();

View file

@ -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<S> ::axum::extract::FromRequestParts<S> 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<S> ::axum::extract::FromRequestParts<S> for #ident
where
@ -322,7 +320,6 @@ fn expand_unit_fields(
};
let from_request_impl = quote! {
#[::axum::async_trait]
#[automatically_derived]
impl<S> ::axum::extract::FromRequestParts<S> for #ident
where

View file

@ -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<S> FromRequest<S> for A
where
S: Send + Sync,

View file

@ -1,5 +1,5 @@
error: Handlers must only take owned values
--> tests/debug_handler/fail/extract_self_mut.rs:23:22
--> tests/debug_handler/fail/extract_self_mut.rs:19:22
|
23 | async fn handler(&mut self) {}
19 | async fn handler(&mut self) {}
| ^^^^^^^^^

View file

@ -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<S> FromRequest<S> for A
where
S: Send + Sync,

View file

@ -1,5 +1,5 @@
error: Handlers must only take owned values
--> tests/debug_handler/fail/extract_self_ref.rs:23:22
--> tests/debug_handler/fail/extract_self_ref.rs:19:22
|
23 | async fn handler(&self) {}
19 | async fn handler(&self) {}
| ^^^^^

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

View file

@ -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<S> FromRequest<S> for A
where
S: Send + Sync,
@ -18,7 +14,6 @@ where
}
}
#[async_trait]
impl<S> FromRequest<S> for Box<A>
where
S: Send + Sync,

View file

@ -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<S> FromRequest<S> for A
where
S: Send + Sync,

View file

@ -1,8 +1,8 @@
error[E0277]: the trait bound `String: FromRequestParts<S>` is not satisfied
error[E0277]: the trait bound `String: FromRequestParts<_>` is not satisfied
--> tests/from_request/fail/parts_extracting_body.rs:5:11
|
5 | body: String,
| ^^^^^^ the trait `FromRequestParts<S>` is not implemented for `String`
| ^^^^^^ the trait `FromRequestParts<_>` is not implemented for `String`
|
= note: Function argument is not a valid axum extractor.
See `https://docs.rs/axum/0.7/axum/extract/index.html` for details

View file

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

View file

@ -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<S> FromRequestParts<S> for OtherExtractor
where
S: Send + Sync,

View file

@ -1,9 +1,11 @@
error[E0277]: the trait bound `MyPath: serde::de::DeserializeOwned` is not satisfied
error[E0277]: the trait bound `for<'de> MyPath: serde::de::Deserialize<'de>` is not satisfied
--> tests/typed_path/fail/not_deserialize.rs:3:10
|
3 | #[derive(TypedPath)]
| ^^^^^^^^^ the trait `for<'de> serde::de::Deserialize<'de>` is not implemented for `MyPath`, which is required by `axum::extract::Path<MyPath>: FromRequestParts<S>`
|
= note: for local types consider adding `#[derive(serde::Deserialize)]` to your `MyPath` type
= note: for types from other crates check whether the crate offers a `serde` feature flag
= help: the following other types implement trait `serde::de::Deserialize<'de>`:
&'a [u8]
&'a serde_json::raw::RawValue
@ -16,7 +18,6 @@ error[E0277]: the trait bound `MyPath: serde::de::DeserializeOwned` is not satis
and $N others
= note: required for `MyPath` to implement `serde::de::DeserializeOwned`
= note: required for `axum::extract::Path<MyPath>` to implement `FromRequestParts<S>`
= note: this error originates in the derive macro `TypedPath` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `MyPath: serde::de::DeserializeOwned` is not satisfied
--> tests/typed_path/fail/not_deserialize.rs:3:10
@ -36,4 +37,23 @@ error[E0277]: the trait bound `MyPath: serde::de::DeserializeOwned` is not satis
and $N others
= note: required for `MyPath` to implement `serde::de::DeserializeOwned`
= note: required for `axum::extract::Path<MyPath>` to implement `FromRequestParts<S>`
= note: this error originates in the attribute macro `::axum::async_trait` (in Nightly builds, run with -Z macro-backtrace for more info)
error[E0277]: the trait bound `MyPath: serde::de::DeserializeOwned` is not satisfied
--> tests/typed_path/fail/not_deserialize.rs:3:10
|
3 | #[derive(TypedPath)]
| ^^^^^^^^^ the trait `for<'de> serde::de::Deserialize<'de>` is not implemented for `MyPath`, which is required by `axum::extract::Path<MyPath>: FromRequestParts<S>`
|
= help: the following other types implement trait `serde::de::Deserialize<'de>`:
&'a [u8]
&'a serde_json::raw::RawValue
&'a std::path::Path
&'a str
()
(T,)
(T0, T1)
(T0, T1, T2)
and $N others
= note: required for `MyPath` to implement `serde::de::DeserializeOwned`
= note: required for `axum::extract::Path<MyPath>` to implement `FromRequestParts<S>`
= note: this error originates in the derive macro `TypedPath` (in Nightly builds, run with -Z macro-backtrace for more info)

View file

@ -626,7 +626,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
```rust
struct MyExtractor { /* ... */ }
#[async_trait]
impl<B> FromRequest<B> for MyExtractor
where
B: Send,
@ -645,13 +644,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<S> FromRequestParts<S> for MyExtractor
where
S: Send + Sync,
@ -664,7 +661,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<S, B> FromRequest<S, B> for MyExtractor
where
S: Send + Sync,
@ -1212,7 +1208,6 @@ Yanked, as it didn't compile in release mode.
```rust
struct MyExtractor { /* ... */ }
#[async_trait]
impl<B> FromRequest<B> for MyExtractor
where
B: Send,
@ -1231,13 +1226,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<S> FromRequestParts<S> for MyExtractor
where
S: Send + Sync,
@ -1250,7 +1243,6 @@ Yanked, as it didn't compile in release mode.
}
// implement `FromRequest` if you do need to consume the request body
#[async_trait]
impl<S, B> FromRequest<S, B> for MyExtractor
where
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"]
[dependencies]
async-trait = "0.1.67"
axum-core = { path = "../axum-core", version = "0.4.5" }
bytes = "1.0"
futures-util = { version = "0.3", default-features = false, features = ["alloc"] }
@ -199,7 +198,6 @@ allowed = [
"tower_service",
# >=1.0
"async_trait",
"bytes",
"http",
"http_body",

View file

@ -409,7 +409,6 @@ request body:
```rust,no_run
use axum::{
async_trait,
extract::FromRequestParts,
routing::get,
Router,
@ -422,7 +421,6 @@ use axum::{
struct ExtractUserAgent(HeaderValue);
#[async_trait]
impl<S> FromRequestParts<S> for ExtractUserAgent
where
S: Send + Sync,
@ -452,7 +450,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},
@ -466,7 +463,6 @@ use axum::{
struct ValidatedBody(Bytes);
#[async_trait]
impl<S> FromRequest<S> for ValidatedBody
where
Bytes: FromRequest<S>,
@ -506,7 +502,6 @@ use axum::{
extract::{FromRequest, Request, FromRequestParts},
http::request::Parts,
body::Body,
async_trait,
};
use std::convert::Infallible;
@ -514,7 +509,6 @@ use std::convert::Infallible;
struct MyExtractor;
// `MyExtractor` implements both `FromRequest`
#[async_trait]
impl<S> FromRequest<S> for MyExtractor
where
S: Send + Sync,
@ -528,7 +522,6 @@ where
}
// and `FromRequestParts`
#[async_trait]
impl<S> FromRequestParts<S> for MyExtractor
where
S: Send + Sync,
@ -562,7 +555,6 @@ in your implementation.
```rust
use axum::{
async_trait,
extract::{Extension, FromRequestParts},
http::{StatusCode, HeaderMap, request::Parts},
response::{IntoResponse, Response},
@ -579,7 +571,6 @@ struct AuthenticatedUser {
// ...
}
#[async_trait]
impl<S> FromRequestParts<S> for AuthenticatedUser
where
S: Send + Sync,
@ -633,7 +624,6 @@ use axum::{
routing::get,
extract::{Request, FromRequest, FromRequestParts},
http::{HeaderMap, request::Parts},
async_trait,
};
use std::time::{Instant, Duration};
@ -644,7 +634,6 @@ struct Timing<E> {
}
// we must implement both `FromRequestParts`
#[async_trait]
impl<S, T> FromRequestParts<S> for Timing<T>
where
S: Send + Sync,
@ -664,7 +653,6 @@ where
}
// and `FromRequest`
#[async_trait]
impl<S, T> FromRequest<S> for Timing<T>
where
S: Send + Sync,

View file

@ -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<T>(pub T);
#[async_trait]
impl<T, S> FromRequestParts<S> for Extension<T>
where
T: Clone + Send + Sync + 'static,

View file

@ -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<T>(pub T);
#[async_trait]
impl<S, T> FromRequestParts<S> for ConnectInfo<T>
where
S: Send + Sync,

View file

@ -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<S> FromRequestParts<S> for Host
where
S: Send + Sync,

View file

@ -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<S> FromRequestParts<S> for MatchedPath
where
S: Send + Sync,

View file

@ -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<S> FromRequest<S> for Multipart
where
S: Send + Sync,

View file

@ -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<S> FromRequestParts<S> for NestedPath
where
S: Send + Sync,

View file

@ -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<T>(pub T);
axum_core::__impl_deref!(Path);
#[async_trait]
impl<T, S> FromRequestParts<S> for Path<T>
where
T: DeserializeOwned + Send,
@ -446,7 +444,6 @@ impl std::error::Error for FailedToDeserializePathParams {}
#[derive(Debug)]
pub struct RawPathParams(Vec<(Arc<str>, PercentDecodedStr)>);
#[async_trait]
impl<S> FromRequestParts<S> for RawPathParams
where
S: Send + Sync,

View file

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

View file

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

View file

@ -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<String>);
#[async_trait]
impl<S> FromRequestParts<S> for RawQuery
where
S: Send + Sync,

View file

@ -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<S> FromRequestParts<S> for OriginalUri
where
S: Send + Sync,

View file

@ -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<S> FromRequestParts<S> for MyLibraryExtractor
/// where
/// // keep `S` generic but require that it can produce a `MyLibraryState`
@ -344,7 +341,6 @@ use std::{
#[derive(Debug, Default, Clone, Copy)]
pub struct State<S>(pub S);
#[async_trait]
impl<OuterState, InnerState> FromRequestParts<OuterState> for State<InnerState>
where
InnerState: FromRef<OuterState>,

View file

@ -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<S> FromRequestParts<S> for WebSocketUpgrade<DefaultOnFailedUpgrade>
where
S: Send + Sync,

View file

@ -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<T>(pub T);
#[async_trait]
impl<T, S> FromRequest<S> for Form<T>
where
T: DeserializeOwned,

View file

@ -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::{
@ -91,7 +90,6 @@ use serde::{de::DeserializeOwned, Serialize};
#[must_use]
pub struct Json<T>(pub T);
#[async_trait]
impl<T, S> FromRequest<S> for Json<T>
where
T: DeserializeOwned,

View file

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

View file

@ -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<S> FromRequestParts<S> 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<S> FromRequestParts<S> for RequireAuth
where
S: Send + Sync,
@ -367,7 +364,6 @@ mod tests {
fn works_with_request_body_limit() {
struct MyExtractor;
#[async_trait]
impl<S> FromRequestParts<S> for MyExtractor
where
S: Send + Sync,

View file

@ -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<S> FromRequest<S> for BufferRequestBody
where
S: Send + Sync,

View file

@ -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<Value>) -> impl IntoResponse {
// We define our own `Json` extractor that customizes the error from `axum::Json`
pub struct Json<T>(pub T);
#[async_trait]
impl<S, T> FromRequest<S> for Json<T>
where
axum::Json<T>: FromRequest<S, Rejection = JsonRejection>,

View file

@ -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>(T);
#[async_trait]
impl<S, T> FromRequestParts<S> for Path<T>
where
// 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
use axum::{
async_trait,
extract::{FromRef, FromRequestParts, State},
http::{request::Parts, StatusCode},
response::Json,
@ -102,7 +101,6 @@ struct DatabaseConnection(
bb8::PooledConnection<'static, AsyncDieselConnectionManager<AsyncPgConnection>>,
);
#[async_trait]
impl<S> FromRequestParts<S> for DatabaseConnection
where
S: Send + Sync,

View file

@ -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<S> FromRequestParts<S> for Claims
where
S: Send + Sync,

View file

@ -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},
@ -254,7 +253,6 @@ impl IntoResponse for AuthRedirect {
}
}
#[async_trait]
impl<S> FromRequestParts<S> for User
where
MemoryStore: FromRef<S>,

View file

@ -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<Payload>) {
struct JsonOrForm<T>(T);
#[async_trait]
impl<S, T> FromRequest<S> for JsonOrForm<T>
where
S: Send + Sync,

View file

@ -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<sqlx::Postgres>);
#[async_trait]
impl<S> FromRequestParts<S> for DatabaseConnection
where
PgPool: FromRef<S>,

View file

@ -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<NoTls>>);
#[async_trait]
impl<S> FromRequestParts<S> for DatabaseConnection
where
ConnectionPool: FromRef<S>,

View file

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

View file

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

View file

@ -10,7 +10,6 @@
//! -> <h1>Hello, LT!</h1>
//! ```
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<NameInput>) -> Html<String>
#[derive(Debug, Clone, Copy, Default)]
pub struct ValidatedForm<T>(pub T);
#[async_trait]
impl<T, S> FromRequest<S> for ValidatedForm<T>
where
T: DeserializeOwned + Validate,

View file

@ -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<S> FromRequestParts<S> for Version
where
S: Send + Sync,