take advantage of multiple paths

This commit is contained in:
Jonathan de Jong 2022-02-13 12:07:00 +01:00
parent 0c4b42ac13
commit b8d92d3cec
3 changed files with 29 additions and 23 deletions

View file

@ -387,13 +387,19 @@ macro_rules! impl_ruma_handler {
E: IntoResponse,
$( $ty: FromRequest<axum::body::Body> + Send + 'static, )*
{
fn add_to_router(self, router: Router) -> Router {
fn add_to_router(self, mut router: Router) -> Router {
let meta = Req::Incoming::METADATA;
let method_filter = method_to_filter(meta.method);
router.route(meta.path, on(method_filter, |$( $ty: $ty, )* req| async move {
self($($ty,)* req).await.map(RumaResponse)
}))
for path in IntoIterator::into_iter([meta.unstable_path, meta.r0_path, meta.stable_path]).flatten() {
let this = self.clone();
router = router.route(path, on(method_filter, |$( $ty: $ty, )* req| async move {
this($($ty,)* req).await.map(RumaResponse)
}))
}
router
}
}
};