From f7f2bf662bbf1bfec88750f44b509b3da9ce5441 Mon Sep 17 00:00:00 2001 From: Jose Quintana Date: Wed, 13 Jan 2021 15:43:26 +0100 Subject: [PATCH] feat: some clippy warnings --- Makefile | 5 +++++ src/core/cache.rs | 6 +++--- src/core/rejection.rs | 7 +++++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Makefile b/Makefile index 0a6ff85..bde0065 100644 --- a/Makefile +++ b/Makefile @@ -34,6 +34,11 @@ dev: @cargo make --makefile Makefile.toml watch .PHONY: dev +lint: + @rustc -vV + @cargo clippy --all-features -- -D warnings +.PHONY: lint + build: @rustc -vV @cargo build --release --target $(PKG_TARGET) diff --git a/src/core/cache.rs b/src/core/cache.rs index 685f527..c771cb3 100644 --- a/src/core/cache.rs +++ b/src/core/cache.rs @@ -8,11 +8,11 @@ const CACHE_EXT_ONE_YEAR: [&str; 30] = [ /// It applies the corresponding Cache-Control headers based on a set of file types. pub fn control_headers(res: warp::fs::File) -> warp::reply::WithHeader { // Default max-age value in seconds (one day) - let mut max_age = 60 * 60 * 24 as u64; + let mut max_age = 60 * 60 * 24_u64; if let Some(ext) = res.path().extension() { if let Some(ext) = ext.to_str() { - if CACHE_EXT_ONE_HOUR.iter().any(|n| *n == ext) { + if CACHE_EXT_ONE_HOUR.iter().any(|x| *x == ext) { max_age = 60 * 60; } else if CACHE_EXT_ONE_YEAR.iter().any(|x| *x == ext) { max_age = 60 * 60 * 24 * 365; @@ -34,5 +34,5 @@ pub fn control_headers(res: warp::fs::File) -> warp::reply::WithHeader u32 { - std::cmp::min(n.clone(), u32::MAX as u64) as u32 + std::cmp::min(n, u32::MAX as u64) as u32 } diff --git a/src/core/rejection.rs b/src/core/rejection.rs index d57062f..666eaef 100644 --- a/src/core/rejection.rs +++ b/src/core/rejection.rs @@ -7,9 +7,12 @@ use warp::{Rejection, Reply}; pub async fn handle_rejection(err: Rejection) -> Result { let code = if err.is_not_found() { StatusCode::NOT_FOUND - } else if let Some(_) = err.find::() { + } else if err + .find::() + .is_some() + { StatusCode::BAD_REQUEST - } else if let Some(_) = err.find::() { + } else if err.find::().is_some() { StatusCode::METHOD_NOT_ALLOWED } else { StatusCode::INTERNAL_SERVER_ERROR -- libgit2 1.7.2