diff options
| author | Fuwn <[email protected]> | 2023-04-10 07:23:29 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2023-04-10 07:23:29 +0000 |
| commit | 9934455d4c1857b22a6f54105e54d241f5f61871 (patch) | |
| tree | c0e4165c7ea43200fbeae6d472dc036c58b1079e /src | |
| parent | fix(macros): restrict macro name (diff) | |
| download | windmark-9934455d4c1857b22a6f54105e54d241f5f61871.tar.xz windmark-9934455d4c1857b22a6f54105e54d241f5f61871.zip | |
refactor(partial): into trait
Diffstat (limited to 'src')
| -rw-r--r-- | src/handler/partial.rs | 11 | ||||
| -rw-r--r-- | src/router.rs | 12 |
2 files changed, 16 insertions, 7 deletions
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<T> Partial for T where T: FnMut(RouteContext) -> String + Send + Sync {} +impl<T> 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<AsyncMutex<Box<dyn ErrorResponse>>>, private_key_file_name: String, ca_file_name: String, - headers: Arc<Mutex<Vec<Box<dyn Partial<Output = String>>>>>, - footers: Arc<Mutex<Vec<Box<dyn Partial<Output = String>>>>>, + headers: Arc<Mutex<Vec<Box<dyn Partial>>>>, + footers: Arc<Mutex<Vec<Box<dyn Partial>>>>, ssl_acceptor: Arc<SslAcceptor>, #[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 { |