From c46b2609d949bc39e8015459c810f1f2798af10e Mon Sep 17 00:00:00 2001 From: jdeepee Date: Wed, 28 Oct 2020 10:51:33 +0000 Subject: [PATCH] remove clone bound --- src/middleware/logger.rs | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) diff --git a/src/middleware/logger.rs b/src/middleware/logger.rs index a1d86e754..59ee89879 100644 --- a/src/middleware/logger.rs +++ b/src/middleware/logger.rs @@ -129,19 +129,25 @@ impl Logger { pub fn custom_request_replace( mut self, label: &'static str, - closure: impl Fn(&ServiceRequest) -> String + 'static + Clone, + closure: impl Fn(&ServiceRequest) -> String + 'static, ) -> Self { let inner = Rc::get_mut(&mut self.0).unwrap(); - for tf in inner.format.0.iter_mut() { - if let FormatText::CustomLog(inner_label, inner_closure) = tf { - if inner_label == label { + let pos = inner.format.0.iter().position(|tf| match tf { + FormatText::CustomLog(inner_label, _) => label == inner_label, + _ => false, + }); + match pos { + Some(pos) => match &mut inner.format.0[pos] { + FormatText::CustomLog(_, inner_closure) => { *inner_closure = Some(CustomRequestFn { - inner_fn: Rc::new(closure.clone()), - }); - }; - }; - } + inner_fn: Rc::new(closure), + }) + } + _ => unreachable!(), + }, + None => (), + }; self } }