blob: aaf862329333b962972413b3a5bac4af640b2904 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
|
use axum::extract::{FromRequest, Request, rejection::JsonRejection};
use crate::ErrorResponse;
pub struct ApiJson<T>(pub T);
impl<S, T> FromRequest<S> for ApiJson<T>
where
axum::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(axum::Json::<T>::from_request(req, state).await?.0))
}
}
|