aboutsummaryrefslogtreecommitdiff
path: root/src/router.rs
diff options
context:
space:
mode:
authorFuwn <[email protected]>2023-04-03 02:44:25 +0000
committerFuwn <[email protected]>2023-04-03 02:44:25 +0000
commited52d304178d5d37a0af710f06e8fe8eb65b2c24 (patch)
treea1ce35c6a54d576361a6378c3cf59ea60ebc15e1 /src/router.rs
parentfeat(response): allow multiple languages (diff)
downloadwindmark-ed52d304178d5d37a0af710f06e8fe8eb65b2c24.tar.xz
windmark-ed52d304178d5d37a0af710f06e8fe8eb65b2c24.zip
feat(router): GET RID OF DIRTY BOXES
Diffstat (limited to 'src/router.rs')
-rw-r--r--src/router.rs20
1 files changed, 7 insertions, 13 deletions
diff --git a/src/router.rs b/src/router.rs
index b245722..9917923 100644
--- a/src/router.rs
+++ b/src/router.rs
@@ -16,6 +16,8 @@
// Copyright (C) 2022-2022 Fuwn <[email protected]>
// SPDX-License-Identifier: GPL-3.0-only
+#![allow(clippy::significant_drop_tightening)]
+
use std::{
error::Error,
sync::{Arc, Mutex},
@@ -54,7 +56,7 @@ macro_rules! or_error {
/// response generation, panics, logging, and more.
#[derive(Clone)]
pub struct Router {
- routes: matchit::Router<Arc<Mutex<RouteResponse>>>,
+ routes: matchit::Router<Arc<Mutex<Box<dyn RouteResponse>>>>,
error_handler: Arc<Mutex<ErrorResponse>>,
private_key_file_name: String,
ca_file_name: String,
@@ -123,17 +125,9 @@ impl Router {
/// # Examples
///
/// ```rust
- /// use windmark::Response;
- ///
/// windmark::Router::new()
- /// .mount(
- /// "/",
- /// Box::new(|_| Response::success("This is the index page!")),
- /// )
- /// .mount(
- /// "/test",
- /// Box::new(|_| Response::success("This is a test page!")),
- /// );
+ /// .mount("/", |_| windmark::success!("This is the index page!"))
+ /// .mount("/test", |_| windmark::success!("This is a test page!"));
/// ```
///
/// # Panics
@@ -142,11 +136,11 @@ impl Router {
pub fn mount(
&mut self,
route: impl Into<String> + AsRef<str>,
- handler: RouteResponse,
+ handler: impl RouteResponse + 'static,
) -> &mut Self {
self
.routes
- .insert(route.into(), Arc::new(Mutex::new(handler)))
+ .insert(route.into(), Arc::new(Mutex::new(Box::new(handler))))
.unwrap();
self