From fe92ba2e8cfc29f230a0c8a00f01d82993962e28 Mon Sep 17 00:00:00 2001 From: Nikolay Kim Date: Wed, 30 Nov 2022 17:24:51 +0100 Subject: [PATCH] clippy --- ntex-files/src/error.rs | 2 +- ntex-files/src/lib.rs | 13 +++++-------- ntex-files/src/named.rs | 8 ++++---- ntex-files/src/range.rs | 2 +- 4 files changed, 11 insertions(+), 14 deletions(-) diff --git a/ntex-files/src/error.rs b/ntex-files/src/error.rs index 316d784e..3a25bd1a 100644 --- a/ntex-files/src/error.rs +++ b/ntex-files/src/error.rs @@ -38,7 +38,7 @@ impl WebResponseError for FilesError { } } -#[derive(Display, Debug, PartialEq)] +#[derive(Display, Debug, PartialEq, Eq)] pub enum UriSegmentError { /// The segment started with the wrapped invalid character. #[display(fmt = "The segment started with the wrapped invalid character")] diff --git a/ntex-files/src/lib.rs b/ntex-files/src/lib.rs index fa6730cc..189e2d0d 100644 --- a/ntex-files/src/lib.rs +++ b/ntex-files/src/lib.rs @@ -91,8 +91,8 @@ impl Stream for ChunkedReadFile { let mut file = self.file.take().expect("Use after completion"); self.fut = Some( web::block(move || { - let max_bytes: usize; - max_bytes = cmp::min(size.saturating_sub(counter), 65_536) as usize; + let max_bytes: usize = + cmp::min(size.saturating_sub(counter), 65_536) as usize; let mut buf = Vec::with_capacity(max_bytes); file.seek(io::SeekFrom::Start(offset))?; let nbytes = file.by_ref().take(max_bytes as u64).read_to_end(&mut buf)?; @@ -165,7 +165,7 @@ fn directory_listing(dir: &Directory, req: &HttpRequest) -> Result base.join(p).to_string_lossy().replace("\\", "/"), + Ok(p) if cfg!(windows) => base.join(p).to_string_lossy().replace('\\', "/"), Ok(p) => base.join(p).to_string_lossy().into_owned(), Err(_) => continue, }; @@ -419,7 +419,7 @@ where guards: self.guards.clone(), }; - if let Some(ref default) = self.default.as_ref() { + if let Some(default) = self.default.as_ref() { default .new_service(()) .map(move |result| match result { @@ -491,10 +491,7 @@ where (**guard).check(req.head()) } else { // default behaviour - match *req.method() { - Method::HEAD | Method::GET => true, - _ => false, - } + matches!(*req.method(), Method::HEAD | Method::GET) }; if !is_method_valid { diff --git a/ntex-files/src/named.rs b/ntex-files/src/named.rs index d19db080..8ae4720b 100644 --- a/ntex-files/src/named.rs +++ b/ntex-files/src/named.rs @@ -295,8 +295,8 @@ impl NamedFile { (last_modified, header) } { - let t1: SystemTime = m.clone().into(); - let t2: SystemTime = since.clone().into(); + let t1: SystemTime = (*m).into(); + let t2: SystemTime = (*since).into(); match (t1.duration_since(UNIX_EPOCH), t2.duration_since(UNIX_EPOCH)) { (Ok(t1), Ok(t2)) => t1 > t2, _ => false, @@ -322,8 +322,8 @@ impl NamedFile { } (last_modified, header) } { - let t1: SystemTime = m.clone().into(); - let t2: SystemTime = since.clone().into(); + let t1: SystemTime = (*m).into(); + let t2: SystemTime = (*since).into(); match (t1.duration_since(UNIX_EPOCH), t2.duration_since(UNIX_EPOCH)) { (Ok(t1), Ok(t2)) => t1 <= t2, _ => false, diff --git a/ntex-files/src/range.rs b/ntex-files/src/range.rs index d617a72f..097e6d6c 100644 --- a/ntex-files/src/range.rs +++ b/ntex-files/src/range.rs @@ -80,7 +80,7 @@ impl HttpRange { }) .collect::>()?; - let ranges: Vec = all_ranges.into_iter().filter_map(|x| x).collect(); + let ranges: Vec = all_ranges.into_iter().flatten().collect(); if no_overlap && ranges.is_empty() { return Err(());