From f08e7cd300f2b16ab30d2d1baf0b0fc555971767 Mon Sep 17 00:00:00 2001 From: Rob Ede Date: Sat, 1 Jul 2023 23:47:46 +0100 Subject: [PATCH] address new clippy lints --- actix-web/src/middleware/err_handlers.rs | 4 ++-- actix-web/src/middleware/normalize.rs | 9 ++------- actix-web/src/request_data.rs | 1 - actix-web/src/rmap.rs | 4 ++-- 4 files changed, 6 insertions(+), 12 deletions(-) diff --git a/actix-web/src/middleware/err_handlers.rs b/actix-web/src/middleware/err_handlers.rs index 5522cc021..051a0c6b3 100644 --- a/actix-web/src/middleware/err_handlers.rs +++ b/actix-web/src/middleware/err_handlers.rs @@ -270,8 +270,8 @@ impl ErrorHandlers { handlers .get(status) .map(|h| h.as_ref()) - .or_else(|| status.is_client_error().then(|| default_client).flatten()) - .or_else(|| status.is_server_error().then(|| default_server).flatten()) + .or_else(|| status.is_client_error().then_some(default_client).flatten()) + .or_else(|| status.is_server_error().then_some(default_server).flatten()) } } diff --git a/actix-web/src/middleware/normalize.rs b/actix-web/src/middleware/normalize.rs index 3ab908481..afcc0faac 100644 --- a/actix-web/src/middleware/normalize.rs +++ b/actix-web/src/middleware/normalize.rs @@ -15,11 +15,12 @@ use crate::{ /// /// The default is `TrailingSlash::Trim`. #[non_exhaustive] -#[derive(Debug, Clone, Copy)] +#[derive(Debug, Clone, Copy, Default)] pub enum TrailingSlash { /// Trim trailing slashes from the end of the path. /// /// Using this will require all routes to omit trailing slashes for them to be accessible. + #[default] Trim, /// Only merge any present multiple trailing slashes. @@ -33,12 +34,6 @@ pub enum TrailingSlash { Always, } -impl Default for TrailingSlash { - fn default() -> Self { - TrailingSlash::Trim - } -} - /// Middleware for normalizing a request's path so that routes can be matched more flexibly. /// /// # Normalization Steps diff --git a/actix-web/src/request_data.rs b/actix-web/src/request_data.rs index 719e6551f..bffbf74da 100644 --- a/actix-web/src/request_data.rs +++ b/actix-web/src/request_data.rs @@ -27,7 +27,6 @@ use crate::{ /// # Examples /// ```no_run /// # use actix_web::{web, HttpResponse, HttpRequest, Responder, HttpMessage as _}; -/// /// #[derive(Debug, Clone, PartialEq)] /// struct FlagFromMiddleware(String); /// diff --git a/actix-web/src/rmap.rs b/actix-web/src/rmap.rs index 6e10717c3..8a2ec3297 100644 --- a/actix-web/src/rmap.rs +++ b/actix-web/src/rmap.rs @@ -136,7 +136,7 @@ impl ResourceMap { .root_rmap_fn(String::with_capacity(AVG_PATH_LEN), |mut acc, node| { node.pattern .resource_path_from_iter(&mut acc, &mut elements) - .then(|| acc) + .then_some(acc) }) .ok_or(UrlGenerationError::NotEnoughElements)?; @@ -149,7 +149,7 @@ impl ResourceMap { // external resource; third slash would be the root slash in the path let third_slash_index = path .char_indices() - .filter_map(|(i, c)| (c == '/').then(|| i)) + .filter_map(|(i, c)| (c == '/').then_some(i)) .nth(2) .unwrap_or(path.len());