diff --git a/src/common/accept_ranges.rs b/src/common/accept_ranges.rs index e763fa9d..84da0369 100644 --- a/src/common/accept_ranges.rs +++ b/src/common/accept_ranges.rs @@ -1,5 +1,3 @@ -use http::HeaderValue; - use util::FlatCsv; /// `Accept-Ranges` header, defined in [RFC7233](http://tools.ietf.org/html/rfc7233#section-2.3) @@ -36,12 +34,12 @@ derive_header! { name: ACCEPT_RANGES } -const ACCEPT_RANGES_BYTES: HeaderValue = ::HeaderValue::from_static("bytes"); +const ACCEPT_RANGES_BYTES: &str = "bytes"; impl AcceptRanges { /// A constructor to easily create the common `Accept-Ranges: bytes` header. pub fn bytes() -> Self { - AcceptRanges(ACCEPT_RANGES_BYTES.into()) + AcceptRanges(::HeaderValue::from_static(ACCEPT_RANGES_BYTES).into()) } /// Check if the unit is `bytes`. diff --git a/src/common/access_control_allow_headers.rs b/src/common/access_control_allow_headers.rs index ca3d100d..ad5cff06 100644 --- a/src/common/access_control_allow_headers.rs +++ b/src/common/access_control_allow_headers.rs @@ -41,12 +41,12 @@ derive_header! { impl AccessControlAllowHeaders { /// Returns an iterator over `HeaderName`s contained within. - pub fn iter<'a>(&'a self) -> impl Iterator + 'a { + pub fn iter(&self) -> impl Iterator + '_ { self.0 .iter() .map(|s| s.parse().ok()) .take_while(|val| val.is_some()) - .filter_map(|val| val) + .flatten() } } diff --git a/src/common/access_control_allow_methods.rs b/src/common/access_control_allow_methods.rs index 0fd1438c..e20ee7c1 100644 --- a/src/common/access_control_allow_methods.rs +++ b/src/common/access_control_allow_methods.rs @@ -42,7 +42,7 @@ derive_header! { impl AccessControlAllowMethods { /// Returns an iterator over `Method`s contained within. - pub fn iter<'a>(&'a self) -> impl Iterator + 'a { + pub fn iter(&self) -> impl Iterator + '_ { self.0.iter().filter_map(|s| s.parse().ok()) } } diff --git a/src/common/access_control_allow_origin.rs b/src/common/access_control_allow_origin.rs index 8d38bf17..4d8778a9 100644 --- a/src/common/access_control_allow_origin.rs +++ b/src/common/access_control_allow_origin.rs @@ -105,7 +105,7 @@ impl TryFromValues for OriginOrAny { impl<'a> From<&'a OriginOrAny> for HeaderValue { fn from(origin: &'a OriginOrAny) -> HeaderValue { match origin { - OriginOrAny::Origin(ref origin) => origin.into_value(), + OriginOrAny::Origin(ref origin) => origin.to_value(), OriginOrAny::Any => HeaderValue::from_static("*"), } } diff --git a/src/common/access_control_expose_headers.rs b/src/common/access_control_expose_headers.rs index a9b7a50f..299087a2 100644 --- a/src/common/access_control_expose_headers.rs +++ b/src/common/access_control_expose_headers.rs @@ -42,7 +42,7 @@ derive_header! { impl AccessControlExposeHeaders { /// Returns an iterator over `HeaderName`s contained within. - pub fn iter<'a>(&'a self) -> impl Iterator + 'a { + pub fn iter(&self) -> impl Iterator + '_ { self.0.iter().filter_map(|s| s.parse().ok()) } } diff --git a/src/common/access_control_request_headers.rs b/src/common/access_control_request_headers.rs index 5628d9d5..2f2ef061 100644 --- a/src/common/access_control_request_headers.rs +++ b/src/common/access_control_request_headers.rs @@ -43,7 +43,7 @@ derive_header! { impl AccessControlRequestHeaders { /// Returns an iterator over `HeaderName`s contained within. - pub fn iter<'a>(&'a self) -> impl Iterator + 'a { + pub fn iter(&self) -> impl Iterator + '_ { self.0.iter().filter_map(|s| s.parse().ok()) } } diff --git a/src/common/allow.rs b/src/common/allow.rs index 0285d3c7..9a575972 100644 --- a/src/common/allow.rs +++ b/src/common/allow.rs @@ -44,7 +44,7 @@ derive_header! { impl Allow { /// Returns an iterator over `Method`s contained within. - pub fn iter<'a>(&'a self) -> impl Iterator + 'a { + pub fn iter(&self) -> impl Iterator + '_ { self.0.iter().filter_map(|s| s.parse().ok()) } } diff --git a/src/common/authorization.rs b/src/common/authorization.rs index bb2c35ec..cd528a8c 100644 --- a/src/common/authorization.rs +++ b/src/common/authorization.rs @@ -63,7 +63,7 @@ impl Authorization { pub fn bearer(token: &str) -> Result { HeaderValueString::from_string(format!("Bearer {}", token)) .map(|val| Authorization(Bearer(val))) - .ok_or_else(|| InvalidBearerToken { _inner: () }) + .ok_or(InvalidBearerToken { _inner: () }) } /// View the token part as a `&str`. diff --git a/src/common/cache_control.rs b/src/common/cache_control.rs index 7d5db055..9a612653 100644 --- a/src/common/cache_control.rs +++ b/src/common/cache_control.rs @@ -284,16 +284,16 @@ impl FromIterator for FromIter { cc.flags.insert(Flags::PROXY_REVALIDATE); } Directive::MaxAge(secs) => { - cc.max_age = Some(Duration::from_secs(secs.into()).into()); + cc.max_age = Some(Duration::from_secs(secs).into()); } Directive::MaxStale(secs) => { - cc.max_stale = Some(Duration::from_secs(secs.into()).into()); + cc.max_stale = Some(Duration::from_secs(secs).into()); } Directive::MinFresh(secs) => { - cc.min_fresh = Some(Duration::from_secs(secs.into()).into()); + cc.min_fresh = Some(Duration::from_secs(secs).into()); } Directive::SMaxAge(secs) => { - cc.s_max_age = Some(Duration::from_secs(secs.into()).into()); + cc.s_max_age = Some(Duration::from_secs(secs).into()); } } } @@ -420,7 +420,7 @@ impl FromStr for KnownDirective { "" => return Err(()), _ => match s.find('=') { Some(idx) if idx + 1 < s.len() => { - match (&s[..idx], (&s[idx + 1..]).trim_matches('"')) { + match (&s[..idx], (s[idx + 1..]).trim_matches('"')) { ("max-age", secs) => secs.parse().map(Directive::MaxAge).map_err(|_| ())?, ("max-stale", secs) => { secs.parse().map(Directive::MaxStale).map_err(|_| ())? diff --git a/src/common/connection.rs b/src/common/connection.rs index 00299e47..ff562a35 100644 --- a/src/common/connection.rs +++ b/src/common/connection.rs @@ -87,10 +87,7 @@ impl Connection { /// ``` pub fn contains(&self, name: impl AsConnectionOption) -> bool { let s = name.as_connection_option(); - self.0 - .iter() - .find(|&opt| opt.eq_ignore_ascii_case(s)) - .is_some() + self.0.iter().any(|opt| opt.eq_ignore_ascii_case(s)) } } @@ -112,7 +109,7 @@ mod sealed { impl<'a> AsConnectionOption for &'a str { fn as_connection_option(&self) -> &str { - *self + self } } diff --git a/src/common/content_encoding.rs b/src/common/content_encoding.rs index cee95fcd..83bee36b 100644 --- a/src/common/content_encoding.rs +++ b/src/common/content_encoding.rs @@ -72,7 +72,7 @@ impl ContentEncoding { /// ``` pub fn contains(&self, coding: impl AsCoding) -> bool { let s = coding.as_coding(); - self.0.iter().find(|&opt| opt == s).is_some() + self.0.iter().any(|opt| opt == s) } } @@ -87,7 +87,7 @@ mod sealed { impl<'a> Sealed for &'a str { fn as_coding(&self) -> &str { - *self + self } } } diff --git a/src/common/content_type.rs b/src/common/content_type.rs index 1ae15c2e..5d03362f 100644 --- a/src/common/content_type.rs +++ b/src/common/content_type.rs @@ -1,6 +1,6 @@ use std::fmt; -use mime::{self, Mime}; +use mime::Mime; /// `Content-Type` header, defined in /// [RFC7231](http://tools.ietf.org/html/rfc7231#section-3.1.1.5) diff --git a/src/common/etag.rs b/src/common/etag.rs index 25846b76..a43633b1 100644 --- a/src/common/etag.rs +++ b/src/common/etag.rs @@ -54,7 +54,7 @@ impl FromStr for ETag { EntityTag::from_owned(val) .map(ETag) - .ok_or_else(|| InvalidETag { _inner: () }) + .ok_or(InvalidETag { _inner: () }) } } diff --git a/src/common/origin.rs b/src/common/origin.rs index 6d4a022e..059c6f96 100644 --- a/src/common/origin.rs +++ b/src/common/origin.rs @@ -46,10 +46,7 @@ impl Origin { /// Checks if `Origin` is `null`. #[inline] pub fn is_null(&self) -> bool { - match self.0 { - OriginOrNull::Null => true, - _ => false, - } + matches!(self.0, OriginOrNull::Null) } /// Get the "scheme" part of this origin. @@ -101,7 +98,7 @@ impl Origin { HeaderValue::from_maybe_shared(bytes) .ok() .and_then(|val| Self::try_from_value(&val)) - .ok_or_else(|| InvalidOrigin { _inner: () }) + .ok_or(InvalidOrigin { _inner: () }) } // Used in AccessControlAllowOrigin @@ -109,7 +106,7 @@ impl Origin { OriginOrNull::try_from_value(value).map(Origin) } - pub(super) fn into_value(&self) -> HeaderValue { + pub(super) fn to_value(&self) -> HeaderValue { (&self.0).into() } } diff --git a/src/common/range.rs b/src/common/range.rs index 6d35936d..edf97b61 100644 --- a/src/common/range.rs +++ b/src/common/range.rs @@ -10,7 +10,7 @@ use std::ops::{Bound, RangeBounds}; /// # ABNF /// /// ```text -/// Range = byte-ranges-specifier / other-ranges-specifier +/// Range = byte-ranges-specifier / other-ranges-specifier /// other-ranges-specifier = other-range-unit "=" other-range-set /// other-range-set = 1*VCHAR /// @@ -66,10 +66,10 @@ impl Range { /// /// The length of the content is passed as an argument, and all ranges /// that can be satisfied will be iterated. - pub fn satisfiable_ranges<'a>( - &'a self, + pub fn satisfiable_ranges( + &self, len: u64, - ) -> impl Iterator, Bound)> + 'a { + ) -> impl Iterator, Bound)> + '_ { let s = self .0 .to_str() diff --git a/src/common/sec_websocket_accept.rs b/src/common/sec_websocket_accept.rs index 89ec7c07..9b08e862 100644 --- a/src/common/sec_websocket_accept.rs +++ b/src/common/sec_websocket_accept.rs @@ -40,7 +40,7 @@ fn sign(key: &[u8]) -> SecWebsocketAccept { let mut sha1 = Sha1::default(); sha1.update(key); sha1.update(&b"258EAFA5-E914-47DA-95CA-C5AB0DC85B11"[..]); - let b64 = Bytes::from(ENGINE.encode(&sha1.finalize())); + let b64 = Bytes::from(ENGINE.encode(sha1.finalize())); let val = ::HeaderValue::from_maybe_shared(b64).expect("base64 is a valid value"); diff --git a/src/common/strict_transport_security.rs b/src/common/strict_transport_security.rs index 628b8004..ff8d3b6a 100644 --- a/src/common/strict_transport_security.rs +++ b/src/common/strict_transport_security.rs @@ -111,13 +111,13 @@ fn from_str(s: &str) -> Result { } } }) - .fold(Some((None, None)), |res, dir| match (res, dir) { - (Some((None, sub)), Some(Directive::MaxAge(age))) => Some((Some(age), sub)), - (Some((age, None)), Some(Directive::IncludeSubdomains)) => Some((age, Some(()))), - (Some((Some(_), _)), Some(Directive::MaxAge(_))) - | (Some((_, Some(_))), Some(Directive::IncludeSubdomains)) + .try_fold((None, None), |res, dir| match (res, dir) { + ((None, sub), Some(Directive::MaxAge(age))) => Some((Some(age), sub)), + ((age, None), Some(Directive::IncludeSubdomains)) => Some((age, Some(()))), + ((Some(_), _), Some(Directive::MaxAge(_))) + | ((_, Some(_)), Some(Directive::IncludeSubdomains)) | (_, None) => None, - (res, _) => res, + (res, _) => Some(res), }) .and_then(|res| match res { (Some(age), sub) => Some(StrictTransportSecurity { diff --git a/src/map_ext.rs b/src/map_ext.rs index e80ccda9..c79e59e0 100644 --- a/src/map_ext.rs +++ b/src/map_ext.rs @@ -1,5 +1,4 @@ use super::{Error, Header, HeaderValue}; -use http; /// An extension trait adding "typed" methods to `http::HeaderMap`. pub trait HeaderMapExt: self::sealed::Sealed { diff --git a/src/util/entity.rs b/src/util/entity.rs index 67604be4..c1bda545 100644 --- a/src/util/entity.rs +++ b/src/util/entity.rs @@ -213,7 +213,7 @@ fn check_slice_validity(slice: &[u8]) -> bool { // The debug_assert is just in case we use check_slice_validity in // some new context that didnt come from a HeaderValue. debug_assert!( - (c >= b'\x21' && c <= b'\x7e') | (c >= b'\x80'), + (b'\x21'..=b'\x7e').contains(&c) | (c >= b'\x80'), "EntityTag expects HeaderValue to have check for control characters" ); c != b'"' diff --git a/src/util/flat_csv.rs b/src/util/flat_csv.rs index 7be56c87..1589ebfe 100644 --- a/src/util/flat_csv.rs +++ b/src/util/flat_csv.rs @@ -40,6 +40,7 @@ impl FlatCsv { let mut in_quotes = false; value_str .split(move |c| { + #[allow(clippy::collapsible_else_if)] if in_quotes { if c == '"' { in_quotes = false; @@ -113,7 +114,7 @@ impl<'a, Sep: Separator> FromIterator<&'a HeaderValue> for FlatCsv { .next() .cloned() .map(|val| BytesMut::from(val.as_bytes())) - .unwrap_or_else(|| BytesMut::new()); + .unwrap_or_default(); for val in values { buf.extend_from_slice(&[Sep::BYTE, b' ']); @@ -144,7 +145,7 @@ impl FromIterator for FlatCsv { let mut buf = values .next() .map(|val| BytesMut::from(val.as_bytes())) - .unwrap_or_else(|| BytesMut::new()); + .unwrap_or_default(); for val in values { buf.extend_from_slice(&[Sep::BYTE, b' ']); diff --git a/src/util/http_date.rs b/src/util/http_date.rs index da3f8396..ec58410f 100644 --- a/src/util/http_date.rs +++ b/src/util/http_date.rs @@ -4,7 +4,6 @@ use std::time::SystemTime; use bytes::Bytes; use http::header::HeaderValue; -use httpdate; use super::IterExt; diff --git a/src/util/mod.rs b/src/util/mod.rs index 07fddbfb..0a58fce3 100644 --- a/src/util/mod.rs +++ b/src/util/mod.rs @@ -82,6 +82,6 @@ impl TryFromValues for HeaderValue { where I: Iterator, { - values.next().cloned().ok_or_else(|| ::Error::invalid()) + values.next().cloned().ok_or_else(::Error::invalid) } }