From c360d1d773bbfa9c9cfec97a202cc2b29b141010 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Sat, 15 Apr 2023 02:00:45 +0000 Subject: refactor(hooks): implement call for hooks --- src/handler/hooks/post_route.rs | 14 +++++++++----- src/handler/hooks/pre_route.rs | 10 ++++++++-- 2 files changed, 17 insertions(+), 7 deletions(-) (limited to 'src/handler') 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 PostRouteHook for T where T: FnMut(HookContext, &mut Response) + Send + Sync -{} +impl 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 PreRouteHook for T where T: FnMut(HookContext) + Send + Sync {} +impl PreRouteHook for T +where T: FnMut(HookContext) + Send + Sync +{ + fn call(&mut self, context: HookContext) { (*self)(context) } +} -- cgit v1.2.3