2021-08-03 21:55:48 +02:00
|
|
|
use super::{FromRequest, RequestParts};
|
2021-12-05 18:16:46 +00:00
|
|
|
use crate::response::{IntoResponse, Response};
|
2021-08-03 21:55:48 +02:00
|
|
|
use async_trait::async_trait;
|
|
|
|
|
use std::convert::Infallible;
|
|
|
|
|
|
|
|
|
|
#[async_trait]
|
2022-08-17 17:13:31 +02:00
|
|
|
impl<S, B> FromRequest<S, B> for ()
|
2021-08-03 21:55:48 +02:00
|
|
|
where
|
|
|
|
|
B: Send,
|
2022-08-17 17:13:31 +02:00
|
|
|
S: Send,
|
2021-08-03 21:55:48 +02:00
|
|
|
{
|
|
|
|
|
type Rejection = Infallible;
|
|
|
|
|
|
2022-08-17 17:13:31 +02:00
|
|
|
async fn from_request(_: &mut RequestParts<S, B>) -> Result<(), Self::Rejection> {
|
2021-08-03 21:55:48 +02:00
|
|
|
Ok(())
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
macro_rules! impl_from_request {
|
2021-09-19 17:51:25 +02:00
|
|
|
() => {};
|
2021-08-03 21:55:48 +02:00
|
|
|
|
2021-09-19 17:51:25 +02:00
|
|
|
( $($ty:ident),* $(,)? ) => {
|
2021-08-03 21:55:48 +02:00
|
|
|
#[async_trait]
|
|
|
|
|
#[allow(non_snake_case)]
|
2022-08-17 17:13:31 +02:00
|
|
|
impl<S, B, $($ty,)*> FromRequest<S, B> for ($($ty,)*)
|
2021-08-03 21:55:48 +02:00
|
|
|
where
|
2022-08-17 17:13:31 +02:00
|
|
|
$( $ty: FromRequest<S, B> + Send, )*
|
2021-08-03 21:55:48 +02:00
|
|
|
B: Send,
|
2022-08-17 17:13:31 +02:00
|
|
|
S: Send,
|
2021-08-03 21:55:48 +02:00
|
|
|
{
|
2021-12-05 18:16:46 +00:00
|
|
|
type Rejection = Response;
|
2021-08-03 21:55:48 +02:00
|
|
|
|
2022-08-17 17:13:31 +02:00
|
|
|
async fn from_request(req: &mut RequestParts<S, B>) -> Result<Self, Self::Rejection> {
|
2021-11-28 17:52:18 +00:00
|
|
|
$( let $ty = $ty::from_request(req).await.map_err(|err| err.into_response())?; )*
|
2021-09-19 17:51:25 +02:00
|
|
|
Ok(($($ty,)*))
|
2021-08-03 21:55:48 +02:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|
2021-11-17 20:09:58 +01:00
|
|
|
all_the_tuples!(impl_from_request);
|