Remove B type param (#1751)

Co-authored-by: Jonas Platte <[email protected]>
Co-authored-by: Michael Scofield <[email protected]>
This commit is contained in:
David Pedersen
2023-04-21 17:45:31 +02:00
co-authored by Jonas Platte Michael Scofield
parent 9be0ea934c
commit 4e4c29175f
100 changed files with 966 additions and 1160 deletions
@@ -6,6 +6,7 @@
//! - Complexity: Manually implementing `FromRequest` results on more complex code
use axum::{
async_trait,
body::Body,
extract::{rejection::JsonRejection, FromRequest, MatchedPath},
http::Request,
http::StatusCode,
@@ -22,15 +23,14 @@ pub async fn handler(Json(value): Json<Value>) -> impl IntoResponse {
pub struct Json<T>(pub T);
#[async_trait]
impl<S, B, T> FromRequest<S, B> for Json<T>
impl<S, T> FromRequest<S> for Json<T>
where
axum::Json<T>: FromRequest<S, B, Rejection = JsonRejection>,
axum::Json<T>: FromRequest<S, Rejection = JsonRejection>,
S: Send + Sync,
B: Send + 'static,
{
type Rejection = (StatusCode, axum::Json<Value>);
async fn from_request(req: Request<B>, state: &S) -> Result<Self, Self::Rejection> {
async fn from_request(req: Request<Body>, state: &S) -> Result<Self, Self::Rejection> {
let (mut parts, body) = req.into_parts();
// We can use other extractors to provide better rejection messages.