diff --git a/src/header/common/access_control_allow_origin.rs b/src/header/common/access_control_allow_origin.rs index bf84b20f..03aa31fb 100644 --- a/src/header/common/access_control_allow_origin.rs +++ b/src/header/common/access_control_allow_origin.rs @@ -52,9 +52,8 @@ impl header::Header for AccessControlAllowOrigin { impl header::HeaderFormat for AccessControlAllowOrigin { fn fmt_header(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self { - AccessControlAllowOrigin::Any => write!(f, "*"), - AccessControlAllowOrigin::Value(ref url) => - write!(f, "{}", url) + AccessControlAllowOrigin::Any => f.write_str("*"), + AccessControlAllowOrigin::Value(ref url) => fmt::Display::fmt(url, f) } } } diff --git a/src/header/common/authorization.rs b/src/header/common/authorization.rs index 9ba2a04a..48a89c0f 100644 --- a/src/header/common/authorization.rs +++ b/src/header/common/authorization.rs @@ -45,12 +45,11 @@ impl Header for Authorization where ::Err: 'st } impl HeaderFormat for Authorization where ::Err: 'static { - fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - match ::scheme() { - Some(scheme) => try!(write!(fmt, "{} ", scheme)), - None => () + fn fmt_header(&self, f: &mut fmt::Formatter) -> fmt::Result { + if let Some(scheme) = ::scheme() { + try!(write!(f, "{} ", scheme)) }; - self.0.fmt_scheme(fmt) + self.0.fmt_scheme(f) } } @@ -70,7 +69,7 @@ impl Scheme for String { } fn fmt_scheme(&self, f: &mut fmt::Formatter) -> fmt::Result { - write!(f, "{}", self) + fmt::Display::fmt(self, f) } } @@ -190,4 +189,3 @@ mod tests { bench_header!(raw, Authorization, { vec![b"foo bar baz".to_vec()] }); bench_header!(basic, Authorization, { vec![b"Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==".to_vec()] }); - diff --git a/src/header/common/cache_control.rs b/src/header/common/cache_control.rs index f1def9e1..93f5e228 100644 --- a/src/header/common/cache_control.rs +++ b/src/header/common/cache_control.rs @@ -19,7 +19,7 @@ impl Header for CacheControl { .filter_map(|line| from_one_comma_delimited(&line[..])) .collect::>>() .concat(); - if directives.len() > 0 { + if !directives.is_empty() { Some(CacheControl(directives)) } else { None diff --git a/src/header/common/pragma.rs b/src/header/common/pragma.rs index c8e5ee7a..a8ddaf04 100644 --- a/src/header/common/pragma.rs +++ b/src/header/common/pragma.rs @@ -33,7 +33,6 @@ impl Header for Pragma { parsing::from_one_raw_str(raw).and_then(|s: String| { let slice = &s.to_ascii_lowercase()[..]; match slice { - "" => None, "no-cache" => Some(Pragma::NoCache), _ => Some(Pragma::Ext(s)), } @@ -58,4 +57,6 @@ fn test_parse_header() { let c: Pragma = Header::parse_header([b"FoObar".to_vec()].as_ref()).unwrap(); let d = Pragma::Ext("FoObar".to_string()); assert_eq!(c, d); + let e: Option = Header::parse_header([b"".to_vec()].as_ref()); + assert_eq!(e, None); } diff --git a/src/header/common/set_cookie.rs b/src/header/common/set_cookie.rs index 419e4c8f..c7c35f4f 100644 --- a/src/header/common/set_cookie.rs +++ b/src/header/common/set_cookie.rs @@ -22,16 +22,12 @@ impl Header for SetCookie { fn parse_header(raw: &[Vec]) -> Option { let mut set_cookies = Vec::with_capacity(raw.len()); - for set_cookies_raw in raw.iter() { - match from_utf8(&set_cookies_raw[..]) { - Ok(s) if !s.is_empty() => { - match s.parse() { - Ok(cookie) => set_cookies.push(cookie), - Err(_) => () - } - }, - _ => () - }; + for set_cookies_raw in raw { + if let Ok(s) = from_utf8(&set_cookies_raw[..]) { + if let Ok(cookie) = s.parse() { + set_cookies.push(cookie); + } + } } if !set_cookies.is_empty() { diff --git a/src/header/mod.rs b/src/header/mod.rs index 739ab529..942b282c 100644 --- a/src/header/mod.rs +++ b/src/header/mod.rs @@ -252,10 +252,7 @@ impl<'a> Iterator for HeadersItems<'a> { type Item = HeaderView<'a>; fn next(&mut self) -> Option> { - match self.inner.next() { - Some((k, v)) => Some(HeaderView(k, v)), - None => None - } + self.inner.next().map(|(k, v)| HeaderView(k, v)) } } diff --git a/src/header/parsing.rs b/src/header/parsing.rs index 07ded6c5..957a3f9b 100644 --- a/src/header/parsing.rs +++ b/src/header/parsing.rs @@ -9,10 +9,12 @@ pub fn from_one_raw_str(raw: &[Vec]) -> Option { return None; } // we JUST checked that raw.len() == 1, so raw[0] WILL exist. - match str::from_utf8(&raw[0][..]) { - Ok(s) => str::FromStr::from_str(s).ok(), - Err(_) => None + if let Ok(s) = str::from_utf8(&raw[0][..]) { + if s != "" { + return str::FromStr::from_str(s).ok(); + } } + None } /// Reads a comma-delimited raw header into a Vec. diff --git a/src/header/shared/httpdate.rs b/src/header/shared/httpdate.rs index a61cd329..f89b56db 100644 --- a/src/header/shared/httpdate.rs +++ b/src/header/shared/httpdate.rs @@ -46,12 +46,7 @@ impl FromStr for HttpDate { impl Display for HttpDate { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - let tm = self.0; - let tm = match tm.tm_utcoff { - 0 => tm, - _ => tm.to_utc(), - }; - fmt::Display::fmt(&tm.rfc822(), f) + fmt::Display::fmt(&self.0.to_utc().rfc822(), f) } } diff --git a/src/http.rs b/src/http.rs index 39befa5f..97c58ddc 100644 --- a/src/http.rs +++ b/src/http.rs @@ -300,7 +300,7 @@ impl Write for HttpWriter { } }, EmptyWriter(..) => { - if msg.len() != 0 { + if !msg.is_empty() { error!("Cannot include a body with this kind of message"); } Ok(0) @@ -354,7 +354,7 @@ fn parse, I>(rdr: &mut BufReader) -> HttpResu _partial => () } match try!(rdr.read_into_buf()) { - 0 if rdr.get_buf().len() == 0 => { + 0 if rdr.get_buf().is_empty() => { return Err(HttpIoError(io::Error::new( io::ErrorKind::ConnectionAborted, "Connection closed"