diff --git a/src/chunked.rs b/src/chunked.rs index c1a4d4f..36856ab 100644 --- a/src/chunked.rs +++ b/src/chunked.rs @@ -115,15 +115,13 @@ impl ChunkedDecoder { pending: false, }) } - Poll::Pending => { - return Ok(DecodeResult::Some { - read: 0, - new_state: Some(State::Chunk(new_current, len)), - new_pos, - buffer, - pending: true, - }); - } + Poll::Pending => Ok(DecodeResult::Some { + read: 0, + new_state: Some(State::Chunk(new_current, len)), + new_pos, + buffer, + pending: true, + }), } } diff --git a/src/client.rs b/src/client.rs index 63490db..bfe854a 100644 --- a/src/client.rs +++ b/src/client.rs @@ -207,12 +207,9 @@ where } // Check for Content-Length. - match content_length { - Some(len) => { - let len = len.last().unwrap().as_str().parse::()?; - res.set_body(Body::from_reader(reader.take(len as u64), Some(len))); - } - None => {} + if let Some(len) = content_length { + let len = len.last().unwrap().as_str().parse::()?; + res.set_body(Body::from_reader(reader.take(len as u64), Some(len))); } // Return the response. @@ -231,7 +228,7 @@ impl Read for Encoder { if !self.headers_done { let len = std::cmp::min(self.headers.len() - self.cursor, buf.len()); let range = self.cursor..self.cursor + len; - buf[0..len].copy_from_slice(&mut self.headers[range]); + buf[0..len].copy_from_slice(&self.headers[range]); self.cursor += len; if self.cursor == self.headers.len() { self.headers_done = true; diff --git a/src/date.rs b/src/date.rs index 429c5ee..e80795b 100644 --- a/src/date.rs +++ b/src/date.rs @@ -51,7 +51,7 @@ pub(crate) fn fmt_http_date(d: SystemTime) -> String { } impl HttpDate { - fn is_valid(&self) -> bool { + fn is_valid(self) -> bool { self.second < 60 && self.minute < 60 && self.hour < 24 @@ -160,8 +160,8 @@ fn parse_rfc850_date(s: &[u8]) -> http_types::Result { b"-Dec-" => 12, _ => bail!("Invalid month"), }, - year: year, - week_day: week_day, + year, + week_day, }) } @@ -407,7 +407,7 @@ impl PartialOrd for HttpDate { } fn is_leap_year(year: u16) -> bool { - year % 4 == 0 && (!(year % 100 == 0) || year % 400 == 0) + year % 4 == 0 && (year % 100 != 0 || year % 400 == 0) } #[cfg(test)] diff --git a/src/lib.rs b/src/lib.rs index 76e25ef..53ca637 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -95,6 +95,10 @@ #![deny(missing_debug_implementations, nonstandard_style)] #![warn(missing_docs, missing_doc_code_examples, unreachable_pub)] #![cfg_attr(test, deny(warnings))] +#![allow(clippy::if_same_then_else)] +#![allow(clippy::len_zero)] +#![allow(clippy::match_bool)] +#![allow(clippy::unreadable_literal)] /// The maximum amount of headers parsed on the server. const MAX_HEADERS: usize = 128; diff --git a/src/server.rs b/src/server.rs index da1196f..dc4eafc 100644 --- a/src/server.rs +++ b/src/server.rs @@ -46,7 +46,7 @@ where let req = match timeout(timeout_duration, decode(addr, io.clone())).await { Ok(Ok(Some(r))) => r, Ok(Ok(None)) | Err(TimeoutError { .. }) => break, /* EOF or timeout */ - Ok(Err(e)) => return Err(e).into(), + Ok(Err(e)) => return Err(e), }; // Pass the request to the endpoint and encode the response. diff --git a/tests/common/mod.rs b/tests/common/mod.rs index b48caf1..cc2543d 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -39,18 +39,21 @@ impl TestCase { ) -> TestCase { let request_fixture = File::open(fixture_path(&request_file_path)) .await - .expect(&format!( - "Could not open request fixture file: {:?}", - &fixture_path(request_file_path) - )); - - let response_fixture = - File::open(fixture_path(&response_file_path)) - .await - .expect(&format!( + .unwrap_or_else(|_| { + panic!( + "Could not open request fixture file: {:?}", + &fixture_path(request_file_path) + ) + }); + + let response_fixture = File::open(fixture_path(&response_file_path)) + .await + .unwrap_or_else(|_| { + panic!( "Could not open response fixture file: {:?}", &fixture_path(response_file_path) - )); + ) + }); let temp = tempfile::tempfile().expect("Failed to create tempfile"); let result = Arc::new(Mutex::new(temp.into())); @@ -107,18 +110,15 @@ pub(crate) fn fixture_path(relative_path: &str) -> PathBuf { } pub(crate) fn munge_date(expected: &mut String, actual: &mut String) { - match expected.find("{DATE}") { - Some(i) => { - println!("{}", expected); - match actual.find("date: ") { - Some(j) => { - let eol = actual[j + 6..].find("\r\n").expect("missing eol"); - expected.replace_range(i..i + 6, &actual[j + 6..j + 6 + eol]); - } - None => expected.replace_range(i..i + 6, ""), + if let Some(i) = expected.find("{DATE}") { + println!("{}", expected); + match actual.find("date: ") { + Some(j) => { + let eol = actual[j + 6..].find("\r\n").expect("missing eol"); + expected.replace_range(i..i + 6, &actual[j + 6..j + 6 + eol]); } + None => expected.replace_range(i..i + 6, ""), } - None => {} } }