1use crate::Router;
2
3pub use inventory::submit;
4
5pub trait TypedHandlerRegistrar: Send + Sync + 'static {
7 fn install_route(&self, router: Router) -> Router;
9}
10
11pub trait TypeRouter {
13 fn typed_route<F: TypedHandlerRegistrar>(self, factory: F) -> Self;
15}
16
17impl TypeRouter for Router {
18 fn typed_route<F: TypedHandlerRegistrar>(self, factory: F) -> Self {
19 factory.install_route(self)
20 }
21}
22
23inventory::collect!(&'static dyn TypedHandlerRegistrar);
24
25#[macro_export]
27macro_rules! submit_typed_handler {
28 ($ty:ident) => {
29 ::spring_web::handler::submit! {
30 &$ty as &dyn ::spring_web::handler::TypedHandlerRegistrar
31 }
32 };
33}
34
35pub fn auto_router() -> Router {
37 let mut router = Router::new();
38 for handler in inventory::iter::<&dyn TypedHandlerRegistrar> {
39 router = handler.install_route(router);
40 }
41 router
42}