diff options
| author | Fuwn <[email protected]> | 2026-04-14 09:15:50 +0000 |
|---|---|---|
| committer | Fuwn <[email protected]> | 2026-04-14 09:15:50 +0000 |
| commit | 43092b1cdfd6e1321fb5cf4ca7d50fa5c25d04f1 (patch) | |
| tree | c56dfcab5b666b602b32aed0f5f651e84ee64ea6 /src | |
| parent | perf(context)!: Replace HashMap parameters with Parameters newtype backed by Vec (diff) | |
| download | archived-windmark-43092b1cdfd6e1321fb5cf4ca7d50fa5c25d04f1.tar.xz archived-windmark-43092b1cdfd6e1321fb5cf4ca7d50fa5c25d04f1.zip | |
perf(router)!: Pass RouteContext by reference to Partial headers and footers
Diffstat (limited to 'src')
| -rw-r--r-- | src/handler/partial.rs | 6 | ||||
| -rw-r--r-- | src/router.rs | 10 |
2 files changed, 6 insertions, 10 deletions
diff --git a/src/handler/partial.rs b/src/handler/partial.rs index b8f4057..a52fa59 100644 --- a/src/handler/partial.rs +++ b/src/handler/partial.rs @@ -2,11 +2,11 @@ use crate::context::RouteContext; #[allow(clippy::module_name_repetitions)] pub trait Partial: Send + Sync { - fn call(&mut self, context: RouteContext) -> String; + fn call(&mut self, context: &RouteContext) -> String; } impl<T> Partial for T -where T: FnMut(RouteContext) -> String + Send + Sync +where T: FnMut(&RouteContext) -> String + Send + Sync { - fn call(&mut self, context: RouteContext) -> String { (*self)(context) } + fn call(&mut self, context: &RouteContext) -> String { (*self)(context) } } diff --git a/src/router.rs b/src/router.rs index fe8fadd..d71c961 100644 --- a/src/router.rs +++ b/src/router.rs @@ -223,12 +223,8 @@ impl RequestHandler { let mut headers = self.headers.lock().expect("headers lock poisoned"); for partial_header in &mut *headers { - writeln!( - &mut header, - "{}", - partial_header.call(route_context.clone()), - ) - .expect("failed to write header"); + writeln!(&mut header, "{}", partial_header.call(&route_context),) + .expect("failed to write header"); } } @@ -240,7 +236,7 @@ impl RequestHandler { let _ = write!( &mut footer, "{}{}", - partial_footer.call(route_context.clone()), + partial_footer.call(&route_context), if length > 1 && i != length - 1 { "\n" } else { |