Typed url param extractor

This commit is contained in:
David Pedersen
2021-05-30 16:53:39 +02:00
parent 03fb15e7a7
commit 0b2f791bf4
3 changed files with 69 additions and 27 deletions
+1 -21
View File
@@ -51,27 +51,7 @@ where
}
macro_rules! impl_handler {
( $head:ident $(,)? ) => {
#[async_trait]
#[allow(non_snake_case)]
impl<F, Fut, B, Res, $head> Handler<B, ($head,)> for F
where
F: Fn(Request<Body>, $head) -> Fut + Send + Sync,
Fut: Future<Output = Result<Res, Error>> + Send,
Res: IntoResponse<B>,
$head: FromRequest + Send,
{
type Response = Res;
type Sealed = sealed::Hidden;
async fn call(self, mut req: Request<Body>) -> Result<Self::Response, Error> {
let $head = $head::from_request(&mut req).await?;
let res = self(req, $head).await?;
Ok(res)
}
}
};
() => {};
( $head:ident, $($tail:ident),* $(,)? ) => {
#[async_trait]