From 9934455d4c1857b22a6f54105e54d241f5f61871 Mon Sep 17 00:00:00 2001 From: Fuwn Date: Mon, 10 Apr 2023 07:23:29 +0000 Subject: refactor(partial): into trait --- src/handler/partial.rs | 11 +++++++++-- src/router.rs | 12 +++++++----- 2 files changed, 16 insertions(+), 7 deletions(-) (limited to 'src') diff --git a/src/handler/partial.rs b/src/handler/partial.rs index 1d55b93..aa433e1 100644 --- a/src/handler/partial.rs +++ b/src/handler/partial.rs @@ -18,6 +18,13 @@ use crate::context::RouteContext; -pub trait Partial: FnMut(RouteContext) -> String + Send + Sync {} +#[allow(clippy::module_name_repetitions)] +pub trait Partial: Send + Sync { + fn call(&mut self, context: RouteContext) -> String; +} -impl Partial for T where T: FnMut(RouteContext) -> String + Send + Sync {} +impl Partial for T +where T: FnMut(RouteContext) -> String + Send + Sync +{ + fn call(&mut self, context: RouteContext) -> String { (*self)(context) } +} diff --git a/src/router.rs b/src/router.rs index f5f6725..2f92088 100644 --- a/src/router.rs +++ b/src/router.rs @@ -78,8 +78,8 @@ pub struct Router { error_handler: Arc>>, private_key_file_name: String, ca_file_name: String, - headers: Arc>>>>, - footers: Arc>>>>, + headers: Arc>>>, + footers: Arc>>>, ssl_acceptor: Arc, #[cfg(feature = "logger")] default_logger: bool, @@ -380,8 +380,10 @@ impl Router { ); for partial_header in &mut *self.headers.lock().unwrap() { - header - .push_str(&format!("{}\n", partial_header(route_context.clone()),)); + header.push_str(&format!( + "{}\n", + partial_header.call(route_context.clone()), + )); } for (i, partial_footer) in { @@ -390,7 +392,7 @@ impl Router { } { footer.push_str(&format!( "{}{}", - partial_footer(route_context.clone()), + partial_footer.call(route_context.clone()), if footers_length > 1 && i != footers_length - 1 { "\n" } else { -- cgit v1.2.3