diff options
| author | Fuwn <[email protected]> | 2022-04-27 00:37:25 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2022-04-27 00:37:25 -0700 |
| commit | 707211d3ce14b06537834fdf9070f023fbe979a3 (patch) | |
| tree | 601ed0056f787644fece09712486f693b3714195 /src | |
| parent | refactor: clarify more importants... (diff) | |
| download | locus-707211d3ce14b06537834fdf9070f023fbe979a3.tar.xz locus-707211d3ce14b06537834fdf9070f023fbe979a3.zip | |
refactor(modules): mount module via macros
Diffstat (limited to 'src')
| -rw-r--r-- | src/macros.rs | 14 | ||||
| -rw-r--r-- | src/main.rs | 9 | ||||
| -rw-r--r-- | src/modules/mod.rs | 25 |
3 files changed, 32 insertions, 16 deletions
diff --git a/src/macros.rs b/src/macros.rs index cd964bb..d2f078c 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -97,3 +97,17 @@ macro_rules! batch_mount { )* }; } + +#[macro_export] +macro_rules! stateless { + ($router:ident, $module:tt) => { + $router.attach_stateless($module::module) + }; +} + +#[macro_export] +macro_rules! statelesses { + ($router:ident, $($module:tt),*) => { + $($crate::stateless!($router, $module);)* + }; +} diff --git a/src/main.rs b/src/main.rs index 946d515..3ca2da8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -117,14 +117,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> { time_section(&mut time_mount, "creating router"); time_mounts("module", &mut time_mount, || { - router.attach_stateless(modules::uptime::module); - router.attach_stateless(modules::sitemap::module); - router.attach_stateless(modules::search::module); - router.attach_stateless(modules::remarks::module); - router.attach_stateless(modules::multi_blog::module); - router.attach_stateless(modules::random::module); - router.attach_stateless(modules::r#static::module); - router.attach_stateless(modules::router::module); + stateless!(router, modules); }); std::thread::spawn(search::index); diff --git a/src/modules/mod.rs b/src/modules/mod.rs index b139159..bdbaef1 100644 --- a/src/modules/mod.rs +++ b/src/modules/mod.rs @@ -16,11 +16,20 @@ // Copyright (C) 2022-2022 Fuwn <[email protected]> // SPDX-License-Identifier: GPL-3.0-only -pub mod multi_blog; -pub mod random; -pub mod remarks; -pub mod router; -pub mod search; -pub mod sitemap; -pub mod r#static; -pub mod uptime; +use crate::statelesses; + +mod multi_blog; +mod random; +mod remarks; +mod router; +mod search; +mod sitemap; +mod r#static; +mod uptime; + +pub fn module(router: &mut windmark::Router) { + statelesses!( + router, uptime, sitemap, search, remarks, multi_blog, random, r#static, + router + ); +} |