Skip to content

Commit

Permalink
feat: some clippy warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
joseluisq committed Jan 13, 2021
1 parent c63b549 commit f7f2bf6
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 5 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions src/core/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<warp::fs::File> {
// 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;
Expand All @@ -34,5 +34,5 @@ pub fn control_headers(res: warp::fs::File) -> warp::reply::WithHeader<warp::fs:

/// It caps a duration value at ~136 years.
fn duration(n: u64) -> u32 {
std::cmp::min(n.clone(), u32::MAX as u64) as u32
std::cmp::min(n, u32::MAX as u64) as u32
}
7 changes: 5 additions & 2 deletions src/core/rejection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,12 @@ use warp::{Rejection, Reply};
pub async fn handle_rejection(err: Rejection) -> Result<impl Reply, Infallible> {
let code = if err.is_not_found() {
StatusCode::NOT_FOUND
} else if let Some(_) = err.find::<warp::filters::body::BodyDeserializeError>() {
} else if err
.find::<warp::filters::body::BodyDeserializeError>()
.is_some()
{
StatusCode::BAD_REQUEST
} else if let Some(_) = err.find::<warp::reject::MethodNotAllowed>() {
} else if err.find::<warp::reject::MethodNotAllowed>().is_some() {
StatusCode::METHOD_NOT_ALLOWED
} else {
StatusCode::INTERNAL_SERVER_ERROR
Expand Down

0 comments on commit f7f2bf6

Please sign in to comment.