From 98d96b89a5a28c9434e4a294df1cf157fd774b26 Mon Sep 17 00:00:00 2001 From: Jason Volk Date: Mon, 17 Jun 2024 04:57:41 +0000 Subject: [PATCH] minor reductions Signed-off-by: Jason Volk --- src/router/layers.rs | 27 +++++++++++++-------------- src/service/admin/console.rs | 14 ++++++++++---- 2 files changed, 23 insertions(+), 18 deletions(-) diff --git a/src/router/layers.rs b/src/router/layers.rs index 3c7a5387..c419d653 100644 --- a/src/router/layers.rs +++ b/src/router/layers.rs @@ -84,28 +84,28 @@ fn compression_layer(server: &Server) -> tower_http::compression::CompressionLay #[cfg(feature = "zstd_compression")] { - if server.config.zstd_compression { - compression_layer = compression_layer.zstd(true); + compression_layer = if server.config.zstd_compression { + compression_layer.zstd(true) } else { - compression_layer = compression_layer.no_zstd(); + compression_layer.no_zstd() }; }; #[cfg(feature = "gzip_compression")] { - if server.config.gzip_compression { - compression_layer = compression_layer.gzip(true); + compression_layer = if server.config.gzip_compression { + compression_layer.gzip(true) } else { - compression_layer = compression_layer.no_gzip(); + compression_layer.no_gzip() }; }; #[cfg(feature = "brotli_compression")] { - if server.config.brotli_compression { - compression_layer = compression_layer.br(true); + compression_layer = if server.config.brotli_compression { + compression_layer.br(true) } else { - compression_layer = compression_layer.no_br(); + compression_layer.no_br() }; }; @@ -179,11 +179,10 @@ fn catch_panic(err: Box) -> http::Response(request: &http::Request) -> tracing::Span { - let path = if let Some(path) = request.extensions().get::() { - path.as_str() - } else { - request.uri().path() - }; + let path = request + .extensions() + .get::() + .map_or_else(|| request.uri().path(), |p| p.as_str()); tracing::info_span!("router:", %path) } diff --git a/src/service/admin/console.rs b/src/service/admin/console.rs index 1603a057..31432cda 100644 --- a/src/service/admin/console.rs +++ b/src/service/admin/console.rs @@ -167,10 +167,16 @@ impl Console { } fn set_history(&self, readline: &mut Readline) { - let history = self.history.lock().expect("locked"); - for entry in history.iter().rev() { - readline.add_history_entry(entry.clone()); - } + self.history + .lock() + .expect("locked") + .iter() + .rev() + .for_each(|entry| { + readline + .add_history_entry(entry.clone()) + .expect("added history entry"); + }); } fn add_history(&self, line: String) {