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
@@ -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,
@@ -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>,
@@ -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`
@@ -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,
-2
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,
-2
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>,
@@ -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,
-2
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>,
-2
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>,
-2
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>,
-1
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"
-2
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,
-2
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,