diff options
| author | Fuwn <[email protected]> | 2023-04-16 21:16:53 -0700 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2023-04-16 21:16:53 -0700 |
| commit | c96318553c1d3650f0b1cce2db0af7f41f697e62 (patch) | |
| tree | 34445a4609f8b2d02a5ba3e9d78761750fb24786 /src | |
| parent | refactor(response): rewrite unnecessary macro to function (diff) | |
| download | locus-c96318553c1d3650f0b1cce2db0af7f41f697e62.tar.xz locus-c96318553c1d3650f0b1cce2db0af7f41f697e62.zip | |
refactor(macros): move unnecessary crate-level macros
Diffstat (limited to 'src')
| -rw-r--r-- | src/macros.rs | 49 | ||||
| -rw-r--r-- | src/main.rs | 1 | ||||
| -rw-r--r-- | src/modules/static.rs | 32 |
3 files changed, 31 insertions, 51 deletions
diff --git a/src/macros.rs b/src/macros.rs deleted file mode 100644 index 55fefcd..0000000 --- a/src/macros.rs +++ /dev/null @@ -1,49 +0,0 @@ -// This file is part of Locus <https://github.com/gemrest/locus>. -// Copyright (C) 2022-2022 Fuwn <[email protected]> -// -// This program is free software: you can redistribute it and/or modify -// it under the terms of the GNU General Public License as published by -// the Free Software Foundation, version 3. -// -// This program is distributed in the hope that it will be useful, but -// WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// General Public License for more details. -// -// You should have received a copy of the GNU General Public License -// along with this program. If not, see <http://www.gnu.org/licenses/>. -// -// Copyright (C) 2022-2022 Fuwn <[email protected]> -// SPDX-License-Identifier: GPL-3.0-only - -#[macro_export] -macro_rules! batch_mount { - ("pages", $router:ident, $(($path:literal, $description:literal, $file:literal)),* $(,)?) => { - $( - (*$crate::route::ROUTES.lock().unwrap()) - .insert($path.to_string(), $crate::route::Route::new($description)); - - ($router).mount($path, |context: ::windmark::context::RouteContext| { - let content = - include_str!(concat!("../../content/static/", $file, ".gmi")); - - $crate::route::cache(&context, &content); - $crate::response::success(&content, &context) - }); - )* - }; - ("files", $router:ident, $(($path:literal, $description:literal, $file:literal)),* $(,)?) => { - $( - (*$crate::route::ROUTES.lock().unwrap()) - .insert($path.to_string(), $crate::route::Route::new($description)); - - ($router).mount( - $path, - ::windmark::binary_success_auto!(include_bytes!(concat!( - "../../content/meta/", - $file - ))), - ); - )* - }; -} diff --git a/src/main.rs b/src/main.rs index 10fea13..90a083b 100644 --- a/src/main.rs +++ b/src/main.rs @@ -29,7 +29,6 @@ #![recursion_limit = "128"] #![allow(clippy::cast_precision_loss, clippy::significant_drop_tightening)] -mod macros; mod modules; mod response; mod route; diff --git a/src/modules/static.rs b/src/modules/static.rs index d2535df..c451d76 100644 --- a/src/modules/static.rs +++ b/src/modules/static.rs @@ -16,7 +16,37 @@ // Copyright (C) 2022-2022 Fuwn <[email protected]> // SPDX-License-Identifier: GPL-3.0-only -use crate::batch_mount; +macro_rules! batch_mount { + ("pages", $router:ident, $(($path:literal, $description:literal, $file:literal)),* $(,)?) => { + $( + (*$crate::route::ROUTES.lock().unwrap()) + .insert($path.to_string(), $crate::route::Route::new($description)); + + ($router).mount($path, |context: ::windmark::context::RouteContext| { + let content = + include_str!(concat!("../../content/static/", $file, ".gmi")); + + $crate::route::cache(&context, &content); + $crate::response::success(&content, &context) + }); + )* + }; + ("files", $router:ident, $(($path:literal, $description:literal, $file:literal)),* $(,)?) => { + $( + (*$crate::route::ROUTES.lock().unwrap()) + .insert($path.to_string(), $crate::route::Route::new($description)); + + ($router).mount( + $path, + ::windmark::binary_success_auto!(include_bytes!(concat!( + "../../content/meta/", + $file + ))), + ); + )* + }; +} + pub fn module(router: &mut windmark::Router) { batch_mount!( |