blob: 259e8905c6e3d1e18eb98d8e9a6e090d71237f8f (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
|
use axum::{
Json,
extract::{FromRequest, Request, rejection::JsonRejection},
};
use crate::ErrorResponse;
pub struct ApiJson<T>(pub T);
impl<S, T> FromRequest<S> for ApiJson<T>
where
Json<T>: FromRequest<S, Rejection = JsonRejection>,
S: Send + Sync,
{
type Rejection = ErrorResponse;
#[inline]
async fn from_request(req: Request, state: &S) -> Result<Self, Self::Rejection> {
Ok(Self(Json::from_request(req, state).await?.0))
}
}
|