diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/handler/hooks/post_route.rs | 14 | ||||
| -rw-r--r-- | src/handler/hooks/pre_route.rs | 10 | ||||
| -rw-r--r-- | src/router.rs | 21 |
3 files changed, 30 insertions, 15 deletions
diff --git a/src/handler/hooks/post_route.rs b/src/handler/hooks/post_route.rs index f4a919d..63a20b9 100644 --- a/src/handler/hooks/post_route.rs +++ b/src/handler/hooks/post_route.rs @@ -19,10 +19,14 @@ use crate::{context::HookContext, Response}; #[allow(clippy::module_name_repetitions)] -pub trait PostRouteHook: - FnMut(HookContext, &mut Response) + Send + Sync -{ +pub trait PostRouteHook: Send + Sync { + fn call(&mut self, context: HookContext, response: &mut Response); } -impl<T> PostRouteHook for T where T: FnMut(HookContext, &mut Response) + Send + Sync -{} +impl<T> PostRouteHook for T +where T: FnMut(HookContext, &mut Response) + Send + Sync +{ + fn call(&mut self, context: HookContext, response: &mut Response) { + (*self)(context, response); + } +} diff --git a/src/handler/hooks/pre_route.rs b/src/handler/hooks/pre_route.rs index af5ed9d..ff6162f 100644 --- a/src/handler/hooks/pre_route.rs +++ b/src/handler/hooks/pre_route.rs @@ -19,6 +19,12 @@ use crate::context::HookContext; #[allow(clippy::module_name_repetitions)] -pub trait PreRouteHook: FnMut(HookContext) + Send + Sync {} +pub trait PreRouteHook: Send + Sync { + fn call(&mut self, context: HookContext); +} -impl<T> PreRouteHook for T where T: FnMut(HookContext) + Send + Sync {} +impl<T> PreRouteHook for T +where T: FnMut(HookContext) + Send + Sync +{ + fn call(&mut self, context: HookContext) { (*self)(context) } +} diff --git a/src/router.rs b/src/router.rs index 2f92088..1bb295c 100644 --- a/src/router.rs +++ b/src/router.rs @@ -83,8 +83,8 @@ pub struct Router { ssl_acceptor: Arc<SslAcceptor>, #[cfg(feature = "logger")] default_logger: bool, - pre_route_callback: Arc<Mutex<Box<dyn PreRouteHook<Output = ()>>>>, - post_route_callback: Arc<Mutex<Box<dyn PostRouteHook<Output = ()>>>>, + pre_route_callback: Arc<Mutex<Box<dyn PreRouteHook>>>, + post_route_callback: Arc<Mutex<Box<dyn PostRouteHook>>>, character_set: String, languages: Vec<String>, port: i32, @@ -368,7 +368,10 @@ impl Router { module.on_pre_route(hook_context.clone()); } - (*self.pre_route_callback).lock().unwrap()(hook_context.clone()); + (*self.pre_route_callback) + .lock() + .unwrap() + .call(hook_context.clone()); let mut content = if let Ok(ref route) = route { let footers_length = (*self.footers.lock().unwrap()).len(); @@ -425,10 +428,10 @@ impl Router { module.on_post_route(hook_context.clone()); } - (*self.post_route_callback).lock().unwrap()( - hook_context.clone(), - &mut content, - ); + (*self.post_route_callback) + .lock() + .unwrap() + .call(hook_context.clone(), &mut content); stream .write_all( @@ -886,7 +889,9 @@ impl Default for Router { #[cfg(feature = "logger")] default_logger: false, pre_route_callback: Arc::new(Mutex::new(Box::new(|_| {}))), - post_route_callback: Arc::new(Mutex::new(Box::new(|_, _| {}))), + post_route_callback: Arc::new(Mutex::new(Box::new( + |_, _: &'_ mut Response| {}, + ))), character_set: "utf-8".to_string(), languages: vec!["en".to_string()], port: 1965, |