aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2022-04-16 01:57:11 -0700
committerFuwn <[email protected]>2022-04-16 01:57:11 -0700
commitbf5a6841ffeb29ffcf718b8fbf80fea91074c58e (patch)
treebd529f566412f92b6f4f609832252874acee422a
parentfeat: add explicit licensing terms (diff)
downloadlocus-bf5a6841ffeb29ffcf718b8fbf80fea91074c58e.tar.xz
locus-bf5a6841ffeb29ffcf718b8fbf80fea91074c58e.zip
refactor: route for future use
-rw-r--r--src/macros.rs4
-rw-r--r--src/main.rs6
-rw-r--r--src/route.rs15
3 files changed, 19 insertions, 6 deletions
diff --git a/src/macros.rs b/src/macros.rs
index 0eaa2f1..8507d97 100644
--- a/src/macros.rs
+++ b/src/macros.rs
@@ -44,7 +44,7 @@ macro_rules! success {
macro_rules! mount_page {
($router:ident, $at:literal, $description:literal, $file:literal) => {
(*crate::ROUTES.lock().unwrap())
- .insert($at.to_string(), $description.to_string());
+ .insert($at.to_string(), crate::route::Route::new($description));
($router).mount(
$at,
@@ -62,7 +62,7 @@ macro_rules! mount_page {
macro_rules! mount_file {
($router:ident, $at:literal, $description:literal, $file:literal) => {
(*crate::ROUTES.lock().unwrap())
- .insert($at.to_string(), $description.to_string());
+ .insert($at.to_string(), crate::route::Route::new($description));
($router).mount(
$at,
diff --git a/src/main.rs b/src/main.rs
index c848fb0..f926faf 100644
--- a/src/main.rs
+++ b/src/main.rs
@@ -60,7 +60,7 @@ static DATABASE: SyncLazy<Mutex<PickleDb>> = SyncLazy::new(|| {
}
})
});
-static ROUTES: SyncLazy<Mutex<HashMap<String, String>>> =
+static ROUTES: SyncLazy<Mutex<HashMap<String, route::Route>>> =
SyncLazy::new(|| Mutex::new(HashMap::new()));
#[derive(Template)]
@@ -160,7 +160,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
"# SITEMAP\n\n{}",
(*ROUTES.lock().unwrap())
.iter()
- .map(|(r, d)| format!("=> {} {}", r, d))
+ .map(|(r, d)| format!("=> {} {}", r, d.description))
.collect::<Vec<_>>()
.join("\n")
),
@@ -187,7 +187,7 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
let results = (*ROUTES.lock().unwrap())
.iter()
- .map(|(r, d)| format!("=> {} {}", r, d))
+ .map(|(r, d)| format!("=> {} {}", r, d.description))
.filter(|r| r.to_lowercase().contains(&query.0.to_string()))
.collect::<Vec<_>>()
.join("\n");
diff --git a/src/route.rs b/src/route.rs
index 66d09cc..1c4b128 100644
--- a/src/route.rs
+++ b/src/route.rs
@@ -16,6 +16,19 @@
// Copyright (C) 2022-2022 Fuwn <[email protected]>
// SPDX-License-Identifier: GPL-3.0-only
+pub struct Route {
+ pub description: String,
+ pub text_cache: String,
+}
+impl Route {
+ pub fn new(description: &str) -> Self {
+ Self {
+ description: description.to_string(),
+ text_cache: "".to_string(),
+ }
+ }
+}
+
pub fn hits_from(route: &str) -> i32 {
if let Ok(database) = crate::DATABASE.lock() {
(*database)
@@ -33,6 +46,6 @@ pub fn track_mount(
handler: windmark::handler::RouteResponse,
) {
(*crate::ROUTES.lock().unwrap())
- .insert(route.to_string(), description.to_string());
+ .insert(route.to_string(), Route::new(description));
router.mount(route, handler);
}