aboutsummaryrefslogtreecommitdiff
path: root/src/route.rs
diff options
context:
space:
mode:
authorFuwn <[email protected]>2023-04-06 00:02:11 -0700
committerFuwn <[email protected]>2023-04-06 00:02:11 -0700
commit039acf58ac5a4b16fdb896634affb637b1bdeaad (patch)
tree46caa813e140c5baae75a48268f6a997a5e9951c /src/route.rs
parentfix(docker): copy syntax warning (diff)
downloadlocus-039acf58ac5a4b16fdb896634affb637b1bdeaad.tar.xz
locus-039acf58ac5a4b16fdb896634affb637b1bdeaad.zip
deps(windmark): bump 0.2.5 -> 0.3.1
Diffstat (limited to 'src/route.rs')
-rw-r--r--src/route.rs15
1 files changed, 10 insertions, 5 deletions
diff --git a/src/route.rs b/src/route.rs
index 5c43871..3590f59 100644
--- a/src/route.rs
+++ b/src/route.rs
@@ -16,10 +16,11 @@
// Copyright (C) 2022-2022 Fuwn <[email protected]>
// SPDX-License-Identifier: GPL-3.0-only
-use std::{collections::HashMap, sync::Mutex};
+use std::{collections::HashMap, future::IntoFuture, sync::Mutex};
use once_cell::sync::Lazy;
use tokio::time::Instant;
+use windmark::context::RouteContext;
#[cfg(debug_assertions)]
pub const CACHE_RATE: u64 = 1;
@@ -53,17 +54,21 @@ pub fn hits_from(route: &str) -> i32 {
}
}
-pub fn track_mount(
+pub fn track_mount<F, R>(
router: &mut windmark::Router,
route: &str,
description: &str,
- handler: windmark::handler::RouteResponse,
-) {
+ handler: F,
+) where
+ F: FnMut(RouteContext<'_>) -> R + Send + Sync + 'static,
+ R: IntoFuture<Output = windmark::Response> + Send + 'static,
+ <R as IntoFuture>::IntoFuture: Send,
+{
(*ROUTES.lock().unwrap()).insert(route.to_string(), Route::new(description));
router.mount(route, handler);
}
-pub fn cache(context: &windmark::returnable::RouteContext<'_>, response: &str) {
+pub fn cache(context: &RouteContext<'_>, response: &str) {
static LAST_CACHED: Lazy<Mutex<Instant>> =
Lazy::new(|| Mutex::new(Instant::now()));