diff --git a/src/header/common/access_control_allow_headers.rs b/src/header/common/access_control_allow_headers.rs index 3820bc34..eda90952 100644 --- a/src/header/common/access_control_allow_headers.rs +++ b/src/header/common/access_control_allow_headers.rs @@ -2,7 +2,7 @@ use unicase::UniCase; header! { #[doc="`Access-Control-Allow-Headers` header, part of"] - #[doc="[CORS](www.w3.org/TR/cors/#access-control-allow-headers-response-header)"] + #[doc="[CORS](http://www.w3.org/TR/cors/#access-control-allow-headers-response-header)"] #[doc=""] #[doc="The `Access-Control-Allow-Headers` header indicates, as part of the"] #[doc="response to a preflight request, which header field names can be used"] diff --git a/src/header/common/access_control_allow_methods.rs b/src/header/common/access_control_allow_methods.rs index 40fb63d1..712e0071 100644 --- a/src/header/common/access_control_allow_methods.rs +++ b/src/header/common/access_control_allow_methods.rs @@ -2,7 +2,7 @@ use method::Method; header! { #[doc="`Access-Control-Allow-Methods` header, part of"] - #[doc="[CORS](www.w3.org/TR/cors/#access-control-allow-methods-response-header)"] + #[doc="[CORS](http://www.w3.org/TR/cors/#access-control-allow-methods-response-header)"] #[doc=""] #[doc="The `Access-Control-Allow-Methods` header indicates, as part of the"] #[doc="response to a preflight request, which methods can be used during the"] diff --git a/src/header/common/access_control_max_age.rs b/src/header/common/access_control_max_age.rs index 6cd88cc2..becd0030 100644 --- a/src/header/common/access_control_max_age.rs +++ b/src/header/common/access_control_max_age.rs @@ -1,6 +1,6 @@ header! { #[doc="`Access-Control-Max-Age` header, part of"] - #[doc="[CORS](www.w3.org/TR/cors/#access-control-max-age-response-header)"] + #[doc="[CORS](http://www.w3.org/TR/cors/#access-control-max-age-response-header)"] #[doc=""] #[doc="The `Access-Control-Max-Age` header indicates how long the results of a"] #[doc="preflight request can be cached in a preflight result cache."] diff --git a/src/header/common/access_control_request_headers.rs b/src/header/common/access_control_request_headers.rs index 35f3ddc2..859d5feb 100644 --- a/src/header/common/access_control_request_headers.rs +++ b/src/header/common/access_control_request_headers.rs @@ -2,7 +2,7 @@ use unicase::UniCase; header! { #[doc="`Access-Control-Request-Headers` header, part of"] - #[doc="[CORS](www.w3.org/TR/cors/#access-control-request-headers-request-header)"] + #[doc="[CORS](http://www.w3.org/TR/cors/#access-control-request-headers-request-header)"] #[doc=""] #[doc="The `Access-Control-Request-Headers` header indicates which headers will"] #[doc="be used in the actual request as part of the preflight request."] diff --git a/src/header/common/access_control_request_method.rs b/src/header/common/access_control_request_method.rs index 3ba96754..6c8bdd8f 100644 --- a/src/header/common/access_control_request_method.rs +++ b/src/header/common/access_control_request_method.rs @@ -2,7 +2,7 @@ use method::Method; header! { #[doc="`Access-Control-Request-Method` header, part of"] - #[doc="[CORS](www.w3.org/TR/cors/#access-control-request-method-request-header)"] + #[doc="[CORS](http://www.w3.org/TR/cors/#access-control-request-method-request-header)"] #[doc=""] #[doc="The `Access-Control-Request-Method` header indicates which method will be"] #[doc="used in the actual request as part of the preflight request."] diff --git a/src/header/common/authorization.rs b/src/header/common/authorization.rs index 48a89c0f..b8125c49 100644 --- a/src/header/common/authorization.rs +++ b/src/header/common/authorization.rs @@ -1,11 +1,25 @@ use std::any::Any; -use std::fmt; +use std::fmt::{self, Display}; use std::str::{FromStr, from_utf8}; use std::ops::{Deref, DerefMut}; use serialize::base64::{ToBase64, FromBase64, Standard, Config, Newline}; use header::{Header, HeaderFormat}; -/// The `Authorization` header field. +/// `Authorization` header, defined in [RFC7235](https://tools.ietf.org/html/rfc7235#section-4.2) +/// +/// The `Authorization` header field allows a user agent to authenticate +/// itself with an origin server -- usually, but not necessarily, after +/// receiving a 401 (Unauthorized) response. Its value consists of +/// credentials containing the authentication information of the user +/// agent for the realm of the resource being requested. +/// +/// # ABNF +/// ```plain +/// Authorization = credentials +/// ``` +/// +/// # Example values +/// * `Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==` #[derive(Clone, PartialEq, Debug)] pub struct Authorization(pub S); @@ -69,7 +83,7 @@ impl Scheme for String { } fn fmt_scheme(&self, f: &mut fmt::Formatter) -> fmt::Result { - fmt::Display::fmt(self, f) + Display::fmt(self, f) } } @@ -97,12 +111,12 @@ impl Scheme for Basic { if let Some(ref pass) = self.password { text.push_str(&pass[..]); } - write!(f, "{}", text.as_bytes().to_base64(Config { + f.write_str(&text.as_bytes().to_base64(Config { char_set: Standard, newline: Newline::CRLF, pad: true, line_length: None - })) + })[..]) } } diff --git a/src/header/common/cache_control.rs b/src/header/common/cache_control.rs index 93f5e228..20ddadac 100644 --- a/src/header/common/cache_control.rs +++ b/src/header/common/cache_control.rs @@ -3,7 +3,23 @@ use std::str::FromStr; use header::{Header, HeaderFormat}; use header::parsing::{from_one_comma_delimited, fmt_comma_delimited}; -/// The Cache-Control header. +/// `Cache-Control` header, defined in [RFC7234](https://tools.ietf.org/html/rfc7234#section-5.2) +/// +/// The `Cache-Control` header field is used to specify directives for +/// caches along the request/response chain. Such cache directives are +/// unidirectional in that the presence of a directive in a request does +/// not imply that the same directive is to be given in the response. +/// +/// # ABNF +/// ```plain +/// Cache-Control = 1#cache-directive +/// cache-directive = token [ "=" ( token / quoted-string ) ] +/// ``` +/// +/// # Example values +/// * `no-cache` +/// * `private, community="UCI"` +/// * `max-age=30` #[derive(PartialEq, Clone, Debug)] pub struct CacheControl(pub Vec); @@ -28,8 +44,8 @@ impl Header for CacheControl { } impl HeaderFormat for CacheControl { - fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - fmt_comma_delimited(fmt, &self[..]) + fn fmt_header(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt_comma_delimited(f, &self[..]) } } diff --git a/src/header/common/connection.rs b/src/header/common/connection.rs index 4eef7ae2..32f8d727 100644 --- a/src/header/common/connection.rs +++ b/src/header/common/connection.rs @@ -1,12 +1,29 @@ use header::{Header, HeaderFormat}; -use std::fmt; +use std::fmt::{self, Display}; use std::str::FromStr; use header::parsing::{from_comma_delimited, fmt_comma_delimited}; use unicase::UniCase; pub use self::ConnectionOption::{KeepAlive, Close, ConnectionHeader}; -/// The `Connection` header. +/// `Connection` header, defined in [RFC7230](https://tools.ietf.org/html/rfc7230#section-6.1) +/// +/// The `Connection` header field allows the sender to indicate desired +/// control options for the current connection. In order to avoid +/// confusing downstream recipients, a proxy or gateway MUST remove or +/// replace any received connection options before forwarding the +/// message. +/// +/// # ABNF +/// ```plain +/// Connection = 1#connection-option +/// connection-option = token +/// ``` +/// +/// # Example values +/// * `close` +/// * `upgrade` +/// * `keep-alive` #[derive(Clone, PartialEq, Debug)] pub struct Connection(pub Vec); @@ -33,20 +50,20 @@ pub enum ConnectionOption { impl FromStr for ConnectionOption { type Err = (); fn from_str(s: &str) -> Result { - match s { - "keep-alive" => Ok(KeepAlive), - "close" => Ok(Close), - s => Ok(ConnectionHeader(UniCase(s.to_string()))) - } + Ok(match s { + "keep-alive" => KeepAlive, + "close" => Close, + s => ConnectionHeader(UniCase(s.to_string())), + }) } } -impl fmt::Display for ConnectionOption { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - write!(fmt, "{}", match *self { +impl Display for ConnectionOption { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.write_str(match *self { KeepAlive => "keep-alive", Close => "close", - ConnectionHeader(UniCase(ref s)) => s.as_ref() + ConnectionHeader(UniCase(ref s)) => s, }) } } @@ -62,13 +79,12 @@ impl Header for Connection { } impl HeaderFormat for Connection { - fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fn fmt_header(&self, f: &mut fmt::Formatter) -> fmt::Result { let Connection(ref parts) = *self; - fmt_comma_delimited(fmt, &parts[..]) + fmt_comma_delimited(f, &parts[..]) } } bench_header!(close, Connection, { vec![b"close".to_vec()] }); bench_header!(keep_alive, Connection, { vec![b"keep-alive".to_vec()] }); bench_header!(header, Connection, { vec![b"authorization".to_vec()] }); - diff --git a/src/header/common/cookie.rs b/src/header/common/cookie.rs index fe1829ed..c37db48c 100644 --- a/src/header/common/cookie.rs +++ b/src/header/common/cookie.rs @@ -1,18 +1,22 @@ use header::{Header, HeaderFormat}; -use std::fmt; +use std::fmt::{self, Display}; use std::str::from_utf8; use cookie::Cookie as CookiePair; use cookie::CookieJar; -/// The `Cookie` header. Defined in [RFC6265](tools.ietf.org/html/rfc6265#section-5.4): +/// `Cookie` header, defined in [RFC6265](http://tools.ietf.org/html/rfc6265#section-5.4) /// -/// > If the user agent does attach a Cookie header field to an HTTP -/// > request, the user agent must send the cookie-string -/// > as the value of the header field. +/// If the user agent does attach a Cookie header field to an HTTP +/// request, the user agent must send the cookie-string +/// as the value of the header field. /// -/// > When the user agent generates an HTTP request, the user agent MUST NOT -/// > attach more than one Cookie header field. +/// When the user agent generates an HTTP request, the user agent MUST NOT +/// attach more than one Cookie header field. +/// +/// # Example values +/// * `SID=31d4d96e407aad42` +/// * `SID=31d4d96e407aad42; lang=en-US` #[derive(Clone, PartialEq, Debug)] pub struct Cookie(pub Vec); @@ -48,13 +52,13 @@ impl Header for Cookie { } impl HeaderFormat for Cookie { - fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fn fmt_header(&self, f: &mut fmt::Formatter) -> fmt::Result { let cookies = &self.0; for (i, cookie) in cookies.iter().enumerate() { if i != 0 { - try!(fmt.write_str("; ")); + try!(f.write_str("; ")); } - try!(write!(fmt, "{}", cookie.pair())); + try!(Display::fmt(&cookie.pair(), f)); } Ok(()) } diff --git a/src/header/common/host.rs b/src/header/common/host.rs index 9015724a..018ab01c 100644 --- a/src/header/common/host.rs +++ b/src/header/common/host.rs @@ -65,10 +65,10 @@ impl Header for Host { } impl HeaderFormat for Host { - fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fn fmt_header(&self, f: &mut fmt::Formatter) -> fmt::Result { match self.port { - None | Some(80) | Some(443) => write!(fmt, "{}", self.hostname), - Some(port) => write!(fmt, "{}:{}", self.hostname, port) + None | Some(80) | Some(443) => f.write_str(&self.hostname[..]), + Some(port) => write!(f, "{}:{}", self.hostname, port) } } } @@ -97,4 +97,3 @@ mod tests { } bench_header!(bench, Host, { vec![b"foo.com:3000".to_vec()] }); - diff --git a/src/header/common/if_range.rs b/src/header/common/if_range.rs index 7c59bb60..4454c0c6 100644 --- a/src/header/common/if_range.rs +++ b/src/header/common/if_range.rs @@ -1,4 +1,5 @@ -use header::{self, EntityTag, HttpDate}; +use std::fmt::{self, Display}; +use header::{self, Header, HeaderFormat, EntityTag, HttpDate}; /// `If-Range` header, defined in [RFC7233](http://tools.ietf.org/html/rfc7233#section-3.2) /// @@ -31,7 +32,7 @@ pub enum IfRange { Date(HttpDate), } -impl header::Header for IfRange { +impl Header for IfRange { fn header_name() -> &'static str { "If-Range" } @@ -48,18 +49,17 @@ impl header::Header for IfRange { } } -impl header::HeaderFormat for IfRange { +impl HeaderFormat for IfRange { fn fmt_header(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { match self { - &IfRange::EntityTag(ref x) => write!(f, "{}", x), - &IfRange::Date(ref x) => write!(f, "{}", x), + &IfRange::EntityTag(ref x) => Display::fmt(x, f), + &IfRange::Date(ref x) => Display::fmt(x, f), } } } -impl ::std::fmt::Display for IfRange { - fn fmt(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { - use header::HeaderFormat; +impl Display for IfRange { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { self.fmt_header(f) } } diff --git a/src/header/common/mod.rs b/src/header/common/mod.rs index 741d5d11..7e2d771a 100644 --- a/src/header/common/mod.rs +++ b/src/header/common/mod.rs @@ -258,7 +258,7 @@ macro_rules! header { impl $crate::header::HeaderFormat for $id { fn fmt_header(&self, f: &mut ::std::fmt::Formatter) -> ::std::fmt::Result { match *self { - $id::Any => write!(f, "*"), + $id::Any => f.write_str("*"), $id::Items(ref fields) => $crate::header::parsing::fmt_comma_delimited(f, &fields[..]) } } diff --git a/src/header/common/pragma.rs b/src/header/common/pragma.rs index a8ddaf04..229243a0 100644 --- a/src/header/common/pragma.rs +++ b/src/header/common/pragma.rs @@ -42,10 +42,10 @@ impl Header for Pragma { impl HeaderFormat for Pragma { fn fmt_header(&self, f: &mut fmt::Formatter) -> fmt::Result { - match *self { - Pragma::NoCache => write!(f, "no-cache"), - Pragma::Ext(ref string) => write!(f, "{}", string), - } + f.write_str(match *self { + Pragma::NoCache => "no-cache", + Pragma::Ext(ref string) => &string[..], + }) } } diff --git a/src/header/common/set_cookie.rs b/src/header/common/set_cookie.rs index c7c35f4f..fc958541 100644 --- a/src/header/common/set_cookie.rs +++ b/src/header/common/set_cookie.rs @@ -1,15 +1,59 @@ use header::{Header, HeaderFormat}; -use std::fmt; +use std::fmt::{self, Display}; use std::str::from_utf8; use cookie::Cookie; use cookie::CookieJar; -/// The `Set-Cookie` header +/// `Set-Cookie` header, defined [RFC6265](http://tools.ietf.org/html/rfc6265#section-4.1) +/// +/// The Set-Cookie HTTP response header is used to send cookies from the +/// server to the user agent. /// /// Informally, the Set-Cookie response header contains the header name /// "Set-Cookie" followed by a ":" and a cookie. Each cookie begins with /// a name-value-pair, followed by zero or more attribute-value pairs. +/// +/// # ABNF +/// ```plain +/// set-cookie-header = "Set-Cookie:" SP set-cookie-string +/// set-cookie-string = cookie-pair *( ";" SP cookie-av ) +/// cookie-pair = cookie-name "=" cookie-value +/// cookie-name = token +/// cookie-value = *cookie-octet / ( DQUOTE *cookie-octet DQUOTE ) +/// cookie-octet = %x21 / %x23-2B / %x2D-3A / %x3C-5B / %x5D-7E +/// ; US-ASCII characters excluding CTLs, +/// ; whitespace DQUOTE, comma, semicolon, +/// ; and backslash +/// token = +/// +/// cookie-av = expires-av / max-age-av / domain-av / +/// path-av / secure-av / httponly-av / +/// extension-av +/// expires-av = "Expires=" sane-cookie-date +/// sane-cookie-date = +/// max-age-av = "Max-Age=" non-zero-digit *DIGIT +/// ; In practice, both expires-av and max-age-av +/// ; are limited to dates representable by the +/// ; user agent. +/// non-zero-digit = %x31-39 +/// ; digits 1 through 9 +/// domain-av = "Domain=" domain-value +/// domain-value = +/// ; defined in [RFC1034], Section 3.5, as +/// ; enhanced by [RFC1123], Section 2.1 +/// path-av = "Path=" path-value +/// path-value = +/// secure-av = "Secure" +/// httponly-av = "HttpOnly" +/// extension-av = +/// ``` +/// +/// # Example values +/// * `SID=31d4d96e407aad42` +/// * `lang=en-US; Expires=Wed, 09 Jun 2021 10:18:14 GMT` +/// * `lang=; Expires=Sun, 06 Nov 1994 08:49:37 GMT` +/// * `lang=en-US; Path=/; Domain=example.com` #[derive(Clone, PartialEq, Debug)] pub struct SetCookie(pub Vec); @@ -46,7 +90,7 @@ impl HeaderFormat for SetCookie { if i != 0 { try!(f.write_str("\r\nSet-Cookie: ")); } - try!(write!(f, "{}", cookie)); + try!(Display::fmt(cookie, f)); } Ok(()) } diff --git a/src/header/internals/item.rs b/src/header/internals/item.rs index bfdc9f0c..b9afa8f5 100644 --- a/src/header/internals/item.rs +++ b/src/header/internals/item.rs @@ -94,12 +94,12 @@ fn parse(raw: &Vec>) -> Option fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match *self.raw { Some(ref raw) => { for part in raw.iter() { match from_utf8(&part[..]) { - Ok(s) => try!(fmt.write_str(s)), + Ok(s) => try!(f.write_str(s)), Err(e) => { error!("raw header value is not utf8. header={:?}, error={:?}", part, e); return Err(fmt::Error); @@ -108,7 +108,7 @@ impl fmt::Display for Item { } Ok(()) }, - None => fmt::Display::fmt(&unsafe { self.typed.one() }, fmt) + None => fmt::Display::fmt(&unsafe { self.typed.one() }, f) } } } diff --git a/src/header/mod.rs b/src/header/mod.rs index 942b282c..f14fda29 100644 --- a/src/header/mod.rs +++ b/src/header/mod.rs @@ -57,7 +57,7 @@ pub trait HeaderFormat: fmt::Debug + HeaderClone + Any + Typeable + Send + Sync /// /// This method is not allowed to introduce an Err not produced /// by the passed-in Formatter. - fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result; + fn fmt_header(&self, f: &mut fmt::Formatter) -> fmt::Result; } @@ -224,21 +224,21 @@ impl Headers { } impl fmt::Display for Headers { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { for header in self.iter() { - try!(write!(fmt, "{}\r\n", header)); + try!(write!(f, "{}\r\n", header)); } Ok(()) } } impl fmt::Debug for Headers { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - try!(fmt.write_str("Headers { ")); + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + try!(f.write_str("Headers { ")); for header in self.iter() { - try!(write!(fmt, "{:?}, ", header)); + try!(write!(f, "{:?}, ", header)); } - try!(fmt.write_str("}")); + try!(f.write_str("}")); Ok(()) } } @@ -292,8 +292,8 @@ impl<'a> fmt::Display for HeaderView<'a> { } impl<'a> fmt::Debug for HeaderView<'a> { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - fmt::Display::fmt(self, fmt) + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Display::fmt(self, f) } } @@ -315,8 +315,8 @@ impl<'a> FromIterator> for Headers { impl<'a> fmt::Display for &'a (HeaderFormat + Send + Sync) { #[inline] - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - (**self).fmt_header(fmt) + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + (**self).fmt_header(f) } } @@ -353,14 +353,14 @@ impl Deref for CowStr { } impl fmt::Debug for CowStr { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - fmt::Debug::fmt(&self.0, fmt) + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Debug::fmt(&self.0, f) } } impl fmt::Display for CowStr { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - fmt::Display::fmt(&self.0, fmt) + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fmt::Display::fmt(&self.0, f) } } @@ -460,9 +460,9 @@ mod tests { } impl HeaderFormat for CrazyLength { - fn fmt_header(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fn fmt_header(&self, f: &mut fmt::Formatter) -> fmt::Result { let CrazyLength(ref opt, ref value) = *self; - write!(fmt, "{:?}, {:?}", opt, value) + write!(f, "{:?}, {:?}", opt, value) } } diff --git a/src/header/parsing.rs b/src/header/parsing.rs index 957a3f9b..5d4744de 100644 --- a/src/header/parsing.rs +++ b/src/header/parsing.rs @@ -1,7 +1,7 @@ //! Utility functions for Header implementations. use std::str; -use std::fmt; +use std::fmt::{self, Display}; /// Reads a single raw string when parsing a header pub fn from_one_raw_str(raw: &[Vec]) -> Option { @@ -9,7 +9,7 @@ pub fn from_one_raw_str(raw: &[Vec]) -> Option { return None; } // we JUST checked that raw.len() == 1, so raw[0] WILL exist. - if let Ok(s) = str::from_utf8(&raw[0][..]) { + if let Ok(s) = str::from_utf8(& unsafe { raw.get_unchecked(0) }[..]) { if s != "" { return str::FromStr::from_str(s).ok(); } @@ -24,7 +24,7 @@ pub fn from_comma_delimited(raw: &[Vec]) -> Option> return None; } // we JUST checked that raw.len() == 1, so raw[0] WILL exist. - from_one_comma_delimited(&raw[0][..]) + from_one_comma_delimited(& unsafe { raw.get_unchecked(0) }[..]) } /// Reads a comma-delimited raw string into a Vec. @@ -45,12 +45,12 @@ pub fn from_one_comma_delimited(raw: &[u8]) -> Option> { } /// Format an array into a comma-delimited string. -pub fn fmt_comma_delimited(f: &mut fmt::Formatter, parts: &[T]) -> fmt::Result { +pub fn fmt_comma_delimited(f: &mut fmt::Formatter, parts: &[T]) -> fmt::Result { for (i, part) in parts.iter().enumerate() { - if i > 0 { - try!(write!(f, ", ")); + if i != 0 { + try!(f.write_str(", ")); } - try!(write!(f, "{}", part)); + try!(Display::fmt(part, f)); } Ok(()) } diff --git a/src/header/shared/charset.rs b/src/header/shared/charset.rs index 4fb6da3e..89a133cf 100644 --- a/src/header/shared/charset.rs +++ b/src/header/shared/charset.rs @@ -97,8 +97,8 @@ impl Charset { } impl Display for Charset { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - write!(fmt, "{}", self.name()) + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.write_str(self.name()) } } diff --git a/src/header/shared/encoding.rs b/src/header/shared/encoding.rs index 315df2ca..83e0e976 100644 --- a/src/header/shared/encoding.rs +++ b/src/header/shared/encoding.rs @@ -24,8 +24,8 @@ pub enum Encoding { } impl fmt::Display for Encoding { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { - fmt.write_str(match *self { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + f.write_str(match *self { Chunked => "chunked", Gzip => "gzip", Deflate => "deflate", diff --git a/src/header/shared/entity.rs b/src/header/shared/entity.rs index 4168dc2f..ec722186 100644 --- a/src/header/shared/entity.rs +++ b/src/header/shared/entity.rs @@ -103,10 +103,10 @@ impl EntityTag { } impl Display for EntityTag { - fn fmt(&self, fmt: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { match self.weak { - true => write!(fmt, "W/\"{}\"", self.tag), - false => write!(fmt, "\"{}\"", self.tag), + true => write!(f, "W/\"{}\"", self.tag), + false => write!(f, "\"{}\"", self.tag), } } } @@ -116,10 +116,8 @@ impl FromStr for EntityTag { fn from_str(s: &str) -> Result { let length: usize = s.len(); let slice = &s[..]; - // Early exits: - // 1. The string is empty, or, - // 2. it doesn't terminate in a DQUOTE. - if slice.is_empty() || !slice.ends_with('"') { + // Early exits if it doesn't terminate in a DQUOTE. + if !slice.ends_with('"') { return Err(()); } // The etag is weak if its first char is not a DQUOTE. diff --git a/src/header/shared/language.rs b/src/header/shared/language.rs index e670abd9..59c8450f 100644 --- a/src/header/shared/language.rs +++ b/src/header/shared/language.rs @@ -36,7 +36,7 @@ impl FromStr for Language { impl fmt::Display for Language { fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { - try!(write!(f, "{}", self.primary)); + try!(f.write_str(&self.primary[..])); match self.sub { Some(ref s) => write!(f, "-{}", s), None => Ok(())