diff --git a/benches/client.rs b/benches/client.rs index 07e464c437..d53e1c3858 100644 --- a/benches/client.rs +++ b/benches/client.rs @@ -34,7 +34,7 @@ fn handle(_r: Request, res: Response) { struct Foo; impl hyper::header::Header for Foo { - fn header_name(_: Option) -> &'static str { + fn header_name() -> &'static str { "x-foo" } fn parse_header(_: &[Vec]) -> Option { diff --git a/benches/client_mock_tcp.rs b/benches/client_mock_tcp.rs index 87d415d868..60f2a04bbe 100644 --- a/benches/client_mock_tcp.rs +++ b/benches/client_mock_tcp.rs @@ -50,7 +50,7 @@ impl Writer for MockStream { struct Foo; impl hyper::header::Header for Foo { - fn header_name(_: Option) -> &'static str { + fn header_name() -> &'static str { "x-foo" } fn parse_header(_: &[Vec]) -> Option { diff --git a/src/header/common/accept.rs b/src/header/common/accept.rs index 0bbf7a79bc..60c5fd50b4 100644 --- a/src/header/common/accept.rs +++ b/src/header/common/accept.rs @@ -31,7 +31,7 @@ pub struct Accept(pub Vec>); deref!(Accept => Vec>); impl header::Header for Accept { - fn header_name(_: Option) -> &'static str { + fn header_name() -> &'static str { "Accept" } diff --git a/src/header/common/access_control/allow_headers.rs b/src/header/common/access_control/allow_headers.rs index 7ac934e7af..ced82397ed 100644 --- a/src/header/common/access_control/allow_headers.rs +++ b/src/header/common/access_control/allow_headers.rs @@ -15,7 +15,7 @@ pub struct AccessControlAllowHeaders(pub Vec); impl header::Header for AccessControlAllowHeaders { #[inline] - fn header_name(_: Option) -> &'static str { + fn header_name() -> &'static str { "Access-Control-Allow-Headers" } diff --git a/src/header/common/access_control/allow_methods.rs b/src/header/common/access_control/allow_methods.rs index 37b880040f..a156eb2a81 100644 --- a/src/header/common/access_control/allow_methods.rs +++ b/src/header/common/access_control/allow_methods.rs @@ -16,7 +16,7 @@ pub struct AccessControlAllowMethods(pub Vec); impl header::Header for AccessControlAllowMethods { #[inline] - fn header_name(_: Option) -> &'static str { + fn header_name() -> &'static str { "Access-Control-Allow-Methods" } diff --git a/src/header/common/access_control/allow_origin.rs b/src/header/common/access_control/allow_origin.rs index 292cb367c5..f2448d66a1 100644 --- a/src/header/common/access_control/allow_origin.rs +++ b/src/header/common/access_control/allow_origin.rs @@ -23,7 +23,7 @@ pub enum AccessControlAllowOrigin { impl header::Header for AccessControlAllowOrigin { #[inline] - fn header_name(_: Option) -> &'static str { + fn header_name() -> &'static str { "Access-Control-Allow-Origin" } diff --git a/src/header/common/access_control/max_age.rs b/src/header/common/access_control/max_age.rs index 84dcfc32db..698f4835aa 100644 --- a/src/header/common/access_control/max_age.rs +++ b/src/header/common/access_control/max_age.rs @@ -14,7 +14,7 @@ pub struct AccessControlMaxAge(pub u32); impl header::Header for AccessControlMaxAge { #[inline] - fn header_name(_: Option) -> &'static str { + fn header_name() -> &'static str { "Access-Control-Max-Age" } diff --git a/src/header/common/access_control/request_headers.rs b/src/header/common/access_control/request_headers.rs index 9bf8593061..37e87070e1 100644 --- a/src/header/common/access_control/request_headers.rs +++ b/src/header/common/access_control/request_headers.rs @@ -14,7 +14,7 @@ pub struct AccessControlRequestHeaders(pub Vec); impl header::Header for AccessControlRequestHeaders { #[inline] - fn header_name(_: Option) -> &'static str { + fn header_name() -> &'static str { "Access-Control-Request-Headers" } diff --git a/src/header/common/access_control/request_method.rs b/src/header/common/access_control/request_method.rs index 05c0c08000..7cd6038bf5 100644 --- a/src/header/common/access_control/request_method.rs +++ b/src/header/common/access_control/request_method.rs @@ -15,7 +15,7 @@ pub struct AccessControlRequestMethod(pub Method); impl header::Header for AccessControlRequestMethod { #[inline] - fn header_name(_: Option) -> &'static str { + fn header_name() -> &'static str { "Access-Control-Request-Method" } diff --git a/src/header/common/allow.rs b/src/header/common/allow.rs index 49b1d0c520..d0ee26de83 100644 --- a/src/header/common/allow.rs +++ b/src/header/common/allow.rs @@ -12,7 +12,7 @@ pub struct Allow(pub Vec); deref!(Allow => Vec); impl Header for Allow { - fn header_name(_: Option) -> &'static str { + fn header_name() -> &'static str { "Allow" } diff --git a/src/header/common/authorization.rs b/src/header/common/authorization.rs index 60d447ff87..6b40599057 100644 --- a/src/header/common/authorization.rs +++ b/src/header/common/authorization.rs @@ -23,7 +23,7 @@ impl DerefMut for Authorization { } impl Header for Authorization { - fn header_name(_: Option>) -> &'static str { + fn header_name() -> &'static str { "Authorization" } diff --git a/src/header/common/cache_control.rs b/src/header/common/cache_control.rs index 6b450011d8..930e939aab 100644 --- a/src/header/common/cache_control.rs +++ b/src/header/common/cache_control.rs @@ -10,7 +10,7 @@ pub struct CacheControl(pub Vec); deref!(CacheControl => Vec); impl Header for CacheControl { - fn header_name(_: Option) -> &'static str { + fn header_name() -> &'static str { "Cache-Control" } diff --git a/src/header/common/connection.rs b/src/header/common/connection.rs index c780f98e42..6d9b20c74a 100644 --- a/src/header/common/connection.rs +++ b/src/header/common/connection.rs @@ -50,7 +50,7 @@ impl fmt::String for ConnectionOption { } impl Header for Connection { - fn header_name(_: Option) -> &'static str { + fn header_name() -> &'static str { "Connection" } diff --git a/src/header/common/content_length.rs b/src/header/common/content_length.rs index fe1c380b3b..499f86adac 100644 --- a/src/header/common/content_length.rs +++ b/src/header/common/content_length.rs @@ -12,7 +12,7 @@ pub struct ContentLength(pub u64); deref!(ContentLength => u64); impl Header for ContentLength { - fn header_name(_: Option) -> &'static str { + fn header_name() -> &'static str { "Content-Length" } diff --git a/src/header/common/content_type.rs b/src/header/common/content_type.rs index d329210a2b..ef3f0a6228 100644 --- a/src/header/common/content_type.rs +++ b/src/header/common/content_type.rs @@ -13,7 +13,7 @@ pub struct ContentType(pub Mime); deref!(ContentType => Mime); impl Header for ContentType { - fn header_name(_: Option) -> &'static str { + fn header_name() -> &'static str { "Content-Type" } diff --git a/src/header/common/cookie.rs b/src/header/common/cookie.rs index d2b2298951..8ff6bb36b1 100644 --- a/src/header/common/cookie.rs +++ b/src/header/common/cookie.rs @@ -19,7 +19,7 @@ pub struct Cookies(pub Vec); deref!(Cookies => Vec); impl Header for Cookies { - fn header_name(_: Option) -> &'static str { + fn header_name() -> &'static str { "Cookie" } diff --git a/src/header/common/date.rs b/src/header/common/date.rs index 3311f7d8cb..788daeaa13 100644 --- a/src/header/common/date.rs +++ b/src/header/common/date.rs @@ -13,7 +13,7 @@ pub struct Date(pub Tm); deref!(Date => Tm); impl Header for Date { - fn header_name(_: Option) -> &'static str { + fn header_name() -> &'static str { "Date" } diff --git a/src/header/common/etag.rs b/src/header/common/etag.rs index b38cd0bb65..bea55dbdb5 100644 --- a/src/header/common/etag.rs +++ b/src/header/common/etag.rs @@ -17,7 +17,7 @@ pub struct Etag { } impl Header for Etag { - fn header_name(_: Option) -> &'static str { + fn header_name() -> &'static str { "Etag" } diff --git a/src/header/common/expires.rs b/src/header/common/expires.rs index 530ff1cf8c..af3a5f9823 100644 --- a/src/header/common/expires.rs +++ b/src/header/common/expires.rs @@ -12,7 +12,7 @@ pub struct Expires(pub Tm); deref!(Expires => Tm); impl Header for Expires { - fn header_name(_: Option) -> &'static str { + fn header_name() -> &'static str { "Expires" } diff --git a/src/header/common/host.rs b/src/header/common/host.rs index 72c004b3a7..57956f1d12 100644 --- a/src/header/common/host.rs +++ b/src/header/common/host.rs @@ -19,7 +19,7 @@ pub struct Host { } impl Header for Host { - fn header_name(_: Option) -> &'static str { + fn header_name() -> &'static str { "Host" } diff --git a/src/header/common/if_modified_since.rs b/src/header/common/if_modified_since.rs index 321f5f7cc6..b7de8ebc5e 100644 --- a/src/header/common/if_modified_since.rs +++ b/src/header/common/if_modified_since.rs @@ -12,7 +12,7 @@ pub struct IfModifiedSince(pub Tm); deref!(IfModifiedSince => Tm); impl Header for IfModifiedSince { - fn header_name(_: Option) -> &'static str { + fn header_name() -> &'static str { "If-Modified-Since" } diff --git a/src/header/common/last_modified.rs b/src/header/common/last_modified.rs index 5d3719d55d..9c43adaea8 100644 --- a/src/header/common/last_modified.rs +++ b/src/header/common/last_modified.rs @@ -12,7 +12,7 @@ pub struct LastModified(pub Tm); deref!(LastModified => Tm); impl Header for LastModified { - fn header_name(_: Option) -> &'static str { + fn header_name() -> &'static str { "Last-Modified" } diff --git a/src/header/common/location.rs b/src/header/common/location.rs index 237f5704da..d964b6ba14 100644 --- a/src/header/common/location.rs +++ b/src/header/common/location.rs @@ -19,7 +19,7 @@ pub struct Location(pub String); deref!(Location => String); impl Header for Location { - fn header_name(_: Option) -> &'static str { + fn header_name() -> &'static str { "Location" } diff --git a/src/header/common/mod.rs b/src/header/common/mod.rs index e7a2aa4584..6a62848dfe 100644 --- a/src/header/common/mod.rs +++ b/src/header/common/mod.rs @@ -86,7 +86,7 @@ macro_rules! impl_list_header( deref!($from => $item); impl header::Header for $from { - fn header_name(_: Option<$from>) -> &'static str { + fn header_name() -> &'static str { $name } @@ -116,7 +116,7 @@ macro_rules! impl_header( deref!($from => $item); impl header::Header for $from { - fn header_name(_: Option<$from>) -> &'static str { + fn header_name() -> &'static str { $name } diff --git a/src/header/common/referer.rs b/src/header/common/referer.rs index 8eee7c7b1e..af73645605 100644 --- a/src/header/common/referer.rs +++ b/src/header/common/referer.rs @@ -16,7 +16,7 @@ pub struct Referer(pub String); deref!(Referer => String); impl Header for Referer { - fn header_name(_: Option) -> &'static str { + fn header_name() -> &'static str { "Referer" } diff --git a/src/header/common/set_cookie.rs b/src/header/common/set_cookie.rs index 5e2e964f41..2900428ffe 100644 --- a/src/header/common/set_cookie.rs +++ b/src/header/common/set_cookie.rs @@ -16,7 +16,7 @@ pub struct SetCookie(pub Vec); deref!(SetCookie => Vec); impl Header for SetCookie { - fn header_name(_: Option) -> &'static str { + fn header_name() -> &'static str { "Set-Cookie" } diff --git a/src/header/common/transfer_encoding.rs b/src/header/common/transfer_encoding.rs index f06f6baf20..79ad1b0a0a 100644 --- a/src/header/common/transfer_encoding.rs +++ b/src/header/common/transfer_encoding.rs @@ -22,7 +22,7 @@ pub struct TransferEncoding(pub Vec); deref!(TransferEncoding => Vec); impl Header for TransferEncoding { - fn header_name(_: Option) -> &'static str { + fn header_name() -> &'static str { "Transfer-Encoding" } diff --git a/src/header/common/upgrade.rs b/src/header/common/upgrade.rs index 992505fe95..71996c40e6 100644 --- a/src/header/common/upgrade.rs +++ b/src/header/common/upgrade.rs @@ -39,7 +39,7 @@ impl fmt::String for Protocol { } impl Header for Upgrade { - fn header_name(_: Option) -> &'static str { + fn header_name() -> &'static str { "Upgrade" } diff --git a/src/header/common/user_agent.rs b/src/header/common/user_agent.rs index 5cc0d2fd67..e2230904fb 100644 --- a/src/header/common/user_agent.rs +++ b/src/header/common/user_agent.rs @@ -11,7 +11,7 @@ pub struct UserAgent(pub String); deref!(UserAgent => String); impl Header for UserAgent { - fn header_name(_: Option) -> &'static str { + fn header_name() -> &'static str { "User-Agent" } diff --git a/src/header/common/vary.rs b/src/header/common/vary.rs index d3d60b628e..c91065995f 100644 --- a/src/header/common/vary.rs +++ b/src/header/common/vary.rs @@ -15,7 +15,7 @@ pub enum Vary { } impl Header for Vary { - fn header_name(_: Option) -> &'static str { + fn header_name() -> &'static str { "Vary" } diff --git a/src/header/mod.rs b/src/header/mod.rs index 9dba3252d9..bd4c9fa855 100644 --- a/src/header/mod.rs +++ b/src/header/mod.rs @@ -38,9 +38,8 @@ type HeaderName = UniCase>; pub trait Header: Clone + Any + Send + Sync { /// Returns the name of the header field this belongs to. /// - /// The market `Option` is to hint to the type system which implementation - /// to call. This can be done away with once UFCS arrives. - fn header_name(marker: Option) -> &'static str; + /// This will become an associated constant once available. + fn header_name() -> &'static str; /// Parse a header from a raw stream of bytes. /// /// It's possible that a request can include a header field more than once, @@ -107,8 +106,9 @@ impl Clone for Box { } } +#[inline] fn header_name() -> &'static str { - let name = Header::header_name(None::); + let name = ::header_name(); name } @@ -246,7 +246,7 @@ impl Headers { /// Removes a header from the map, if one existed. /// Returns true if a header has been removed. pub fn remove(&mut self) -> bool { - self.data.remove(&UniCase(Borrowed(Header::header_name(None::)))).is_some() + self.data.remove(&UniCase(Borrowed(header_name::()))).is_some() } /// Returns an iterator over the header fields. @@ -559,7 +559,7 @@ mod tests { struct CrazyLength(Option, usize); impl Header for CrazyLength { - fn header_name(_: Option) -> &'static str { + fn header_name() -> &'static str { "content-length" } fn parse_header(raw: &[Vec]) -> Option { @@ -678,7 +678,7 @@ mod tests { headers.set(ContentLength(11)); for header in headers.iter() { assert!(header.is::()); - assert_eq!(header.name(), Header::header_name(None::)); + assert_eq!(header.name(), ::header_name()); assert_eq!(header.value(), Some(&ContentLength(11))); assert_eq!(header.value_string(), "11".to_string()); }