Files
axum/axum-core/src/extract/tuple.rs
T

42 lines
1.0 KiB
Rust
Raw Normal View History

2021-08-03 21:55:48 +02:00
use super::{FromRequest, RequestParts};
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-08-03 21:55:48 +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
{
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> {
$( let $ty = $ty::from_request(req).await.map_err(|err| err.into_response())?; )*
Ok(($($ty,)*))
2021-08-03 21:55:48 +02:00
}
}
};
}
all_the_tuples!(impl_from_request);