Replace async_trait with AFIT / RPITIT (#2308)

Co-authored-by: Jonas Platte <[email protected]>
This commit is contained in:
Zheng Li
2024-09-28 21:27:11 +00:00
committed by GitHub
co-authored by Jonas Platte
parent dda5a273b5
commit 19101f624d
69 changed files with 116 additions and 267 deletions
+9 -10
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>,
-12
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,
-4
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