refactor(headers): remove marker from header_name method
It is no longer required, as we can use `<H as Header>::header_name()`.
BREAKING CHANGE: Implementations of Header will need to adjust the
    header_name method. It no longer takes any arguments.
			
			
This commit is contained in:
		| @@ -34,7 +34,7 @@ fn handle(_r: Request, res: Response) { | |||||||
| struct Foo; | struct Foo; | ||||||
|  |  | ||||||
| impl hyper::header::Header for Foo { | impl hyper::header::Header for Foo { | ||||||
|     fn header_name(_: Option<Foo>) -> &'static str { |     fn header_name() -> &'static str { | ||||||
|         "x-foo" |         "x-foo" | ||||||
|     } |     } | ||||||
|     fn parse_header(_: &[Vec<u8>]) -> Option<Foo> { |     fn parse_header(_: &[Vec<u8>]) -> Option<Foo> { | ||||||
|   | |||||||
| @@ -50,7 +50,7 @@ impl Writer for MockStream { | |||||||
| struct Foo; | struct Foo; | ||||||
|  |  | ||||||
| impl hyper::header::Header for Foo { | impl hyper::header::Header for Foo { | ||||||
|     fn header_name(_: Option<Foo>) -> &'static str { |     fn header_name() -> &'static str { | ||||||
|         "x-foo" |         "x-foo" | ||||||
|     } |     } | ||||||
|     fn parse_header(_: &[Vec<u8>]) -> Option<Foo> { |     fn parse_header(_: &[Vec<u8>]) -> Option<Foo> { | ||||||
|   | |||||||
| @@ -31,7 +31,7 @@ pub struct Accept(pub Vec<header::QualityItem<mime::Mime>>); | |||||||
| deref!(Accept => Vec<header::QualityItem<mime::Mime>>); | deref!(Accept => Vec<header::QualityItem<mime::Mime>>); | ||||||
|  |  | ||||||
| impl header::Header for Accept { | impl header::Header for Accept { | ||||||
|     fn header_name(_: Option<Accept>) -> &'static str { |     fn header_name() -> &'static str { | ||||||
|         "Accept" |         "Accept" | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -15,7 +15,7 @@ pub struct AccessControlAllowHeaders(pub Vec<String>); | |||||||
|  |  | ||||||
| impl header::Header for AccessControlAllowHeaders { | impl header::Header for AccessControlAllowHeaders { | ||||||
|     #[inline] |     #[inline] | ||||||
|     fn header_name(_: Option<AccessControlAllowHeaders>) -> &'static str { |     fn header_name() -> &'static str { | ||||||
|         "Access-Control-Allow-Headers" |         "Access-Control-Allow-Headers" | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -16,7 +16,7 @@ pub struct AccessControlAllowMethods(pub Vec<method::Method>); | |||||||
|  |  | ||||||
| impl header::Header for AccessControlAllowMethods { | impl header::Header for AccessControlAllowMethods { | ||||||
|     #[inline] |     #[inline] | ||||||
|     fn header_name(_: Option<AccessControlAllowMethods>) -> &'static str { |     fn header_name() -> &'static str { | ||||||
|         "Access-Control-Allow-Methods" |         "Access-Control-Allow-Methods" | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -23,7 +23,7 @@ pub enum AccessControlAllowOrigin { | |||||||
|  |  | ||||||
| impl header::Header for AccessControlAllowOrigin { | impl header::Header for AccessControlAllowOrigin { | ||||||
|     #[inline] |     #[inline] | ||||||
|     fn header_name(_: Option<AccessControlAllowOrigin>) -> &'static str { |     fn header_name() -> &'static str { | ||||||
|         "Access-Control-Allow-Origin" |         "Access-Control-Allow-Origin" | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -14,7 +14,7 @@ pub struct AccessControlMaxAge(pub u32); | |||||||
|  |  | ||||||
| impl header::Header for AccessControlMaxAge { | impl header::Header for AccessControlMaxAge { | ||||||
|     #[inline] |     #[inline] | ||||||
|     fn header_name(_: Option<AccessControlMaxAge>) -> &'static str { |     fn header_name() -> &'static str { | ||||||
|         "Access-Control-Max-Age" |         "Access-Control-Max-Age" | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -14,7 +14,7 @@ pub struct AccessControlRequestHeaders(pub Vec<String>); | |||||||
|  |  | ||||||
| impl header::Header for AccessControlRequestHeaders { | impl header::Header for AccessControlRequestHeaders { | ||||||
|     #[inline] |     #[inline] | ||||||
|     fn header_name(_: Option<AccessControlRequestHeaders>) -> &'static str { |     fn header_name() -> &'static str { | ||||||
|         "Access-Control-Request-Headers" |         "Access-Control-Request-Headers" | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -15,7 +15,7 @@ pub struct AccessControlRequestMethod(pub Method); | |||||||
|  |  | ||||||
| impl header::Header for AccessControlRequestMethod { | impl header::Header for AccessControlRequestMethod { | ||||||
|     #[inline] |     #[inline] | ||||||
|     fn header_name(_: Option<AccessControlRequestMethod>) -> &'static str { |     fn header_name() -> &'static str { | ||||||
|         "Access-Control-Request-Method" |         "Access-Control-Request-Method" | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -12,7 +12,7 @@ pub struct Allow(pub Vec<Method>); | |||||||
| deref!(Allow => Vec<Method>); | deref!(Allow => Vec<Method>); | ||||||
|  |  | ||||||
| impl Header for Allow { | impl Header for Allow { | ||||||
|     fn header_name(_: Option<Allow>) -> &'static str { |     fn header_name() -> &'static str { | ||||||
|         "Allow" |         "Allow" | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -23,7 +23,7 @@ impl<S: Scheme> DerefMut for Authorization<S> { | |||||||
| } | } | ||||||
|  |  | ||||||
| impl<S: Scheme> Header for Authorization<S> { | impl<S: Scheme> Header for Authorization<S> { | ||||||
|     fn header_name(_: Option<Authorization<S>>) -> &'static str { |     fn header_name() -> &'static str { | ||||||
|         "Authorization" |         "Authorization" | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -10,7 +10,7 @@ pub struct CacheControl(pub Vec<CacheDirective>); | |||||||
| deref!(CacheControl => Vec<CacheDirective>); | deref!(CacheControl => Vec<CacheDirective>); | ||||||
|  |  | ||||||
| impl Header for CacheControl { | impl Header for CacheControl { | ||||||
|     fn header_name(_: Option<CacheControl>) -> &'static str { |     fn header_name() -> &'static str { | ||||||
|         "Cache-Control" |         "Cache-Control" | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -50,7 +50,7 @@ impl fmt::String for ConnectionOption { | |||||||
| } | } | ||||||
|  |  | ||||||
| impl Header for Connection { | impl Header for Connection { | ||||||
|     fn header_name(_: Option<Connection>) -> &'static str { |     fn header_name() -> &'static str { | ||||||
|         "Connection" |         "Connection" | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -12,7 +12,7 @@ pub struct ContentLength(pub u64); | |||||||
| deref!(ContentLength => u64); | deref!(ContentLength => u64); | ||||||
|  |  | ||||||
| impl Header for ContentLength { | impl Header for ContentLength { | ||||||
|     fn header_name(_: Option<ContentLength>) -> &'static str { |     fn header_name() -> &'static str { | ||||||
|         "Content-Length" |         "Content-Length" | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -13,7 +13,7 @@ pub struct ContentType(pub Mime); | |||||||
| deref!(ContentType => Mime); | deref!(ContentType => Mime); | ||||||
|  |  | ||||||
| impl Header for ContentType { | impl Header for ContentType { | ||||||
|     fn header_name(_: Option<ContentType>) -> &'static str { |     fn header_name() -> &'static str { | ||||||
|         "Content-Type" |         "Content-Type" | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -19,7 +19,7 @@ pub struct Cookies(pub Vec<Cookie>); | |||||||
| deref!(Cookies => Vec<Cookie>); | deref!(Cookies => Vec<Cookie>); | ||||||
|  |  | ||||||
| impl Header for Cookies { | impl Header for Cookies { | ||||||
|     fn header_name(_: Option<Cookies>) -> &'static str { |     fn header_name() -> &'static str { | ||||||
|         "Cookie" |         "Cookie" | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -13,7 +13,7 @@ pub struct Date(pub Tm); | |||||||
| deref!(Date => Tm); | deref!(Date => Tm); | ||||||
|  |  | ||||||
| impl Header for Date { | impl Header for Date { | ||||||
|     fn header_name(_: Option<Date>) -> &'static str { |     fn header_name() -> &'static str { | ||||||
|         "Date" |         "Date" | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -17,7 +17,7 @@ pub struct Etag { | |||||||
| } | } | ||||||
|  |  | ||||||
| impl Header for Etag { | impl Header for Etag { | ||||||
|     fn header_name(_: Option<Etag>) -> &'static str { |     fn header_name() -> &'static str { | ||||||
|         "Etag" |         "Etag" | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -12,7 +12,7 @@ pub struct Expires(pub Tm); | |||||||
| deref!(Expires => Tm); | deref!(Expires => Tm); | ||||||
|  |  | ||||||
| impl Header for Expires { | impl Header for Expires { | ||||||
|     fn header_name(_: Option<Expires>) -> &'static str { |     fn header_name() -> &'static str { | ||||||
|         "Expires" |         "Expires" | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -19,7 +19,7 @@ pub struct Host { | |||||||
| } | } | ||||||
|  |  | ||||||
| impl Header for Host { | impl Header for Host { | ||||||
|     fn header_name(_: Option<Host>) -> &'static str { |     fn header_name() -> &'static str { | ||||||
|         "Host" |         "Host" | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -12,7 +12,7 @@ pub struct IfModifiedSince(pub Tm); | |||||||
| deref!(IfModifiedSince => Tm); | deref!(IfModifiedSince => Tm); | ||||||
|  |  | ||||||
| impl Header for IfModifiedSince { | impl Header for IfModifiedSince { | ||||||
|     fn header_name(_: Option<IfModifiedSince>) -> &'static str { |     fn header_name() -> &'static str { | ||||||
|         "If-Modified-Since" |         "If-Modified-Since" | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -12,7 +12,7 @@ pub struct LastModified(pub Tm); | |||||||
| deref!(LastModified => Tm); | deref!(LastModified => Tm); | ||||||
|  |  | ||||||
| impl Header for LastModified { | impl Header for LastModified { | ||||||
|     fn header_name(_: Option<LastModified>) -> &'static str { |     fn header_name() -> &'static str { | ||||||
|         "Last-Modified" |         "Last-Modified" | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -19,7 +19,7 @@ pub struct Location(pub String); | |||||||
| deref!(Location => String); | deref!(Location => String); | ||||||
|  |  | ||||||
| impl Header for Location { | impl Header for Location { | ||||||
|     fn header_name(_: Option<Location>) -> &'static str { |     fn header_name() -> &'static str { | ||||||
|         "Location" |         "Location" | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -86,7 +86,7 @@ macro_rules! impl_list_header( | |||||||
|         deref!($from => $item); |         deref!($from => $item); | ||||||
|  |  | ||||||
|         impl header::Header for $from { |         impl header::Header for $from { | ||||||
|             fn header_name(_: Option<$from>) -> &'static str { |             fn header_name() -> &'static str { | ||||||
|                 $name |                 $name | ||||||
|             } |             } | ||||||
|  |  | ||||||
| @@ -116,7 +116,7 @@ macro_rules! impl_header( | |||||||
|         deref!($from => $item); |         deref!($from => $item); | ||||||
|  |  | ||||||
|         impl header::Header for $from { |         impl header::Header for $from { | ||||||
|             fn header_name(_: Option<$from>) -> &'static str { |             fn header_name() -> &'static str { | ||||||
|                 $name |                 $name | ||||||
|             } |             } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -16,7 +16,7 @@ pub struct Referer(pub String); | |||||||
| deref!(Referer => String); | deref!(Referer => String); | ||||||
|  |  | ||||||
| impl Header for Referer { | impl Header for Referer { | ||||||
|     fn header_name(_: Option<Referer>) -> &'static str { |     fn header_name() -> &'static str { | ||||||
|         "Referer" |         "Referer" | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -16,7 +16,7 @@ pub struct SetCookie(pub Vec<Cookie>); | |||||||
| deref!(SetCookie => Vec<Cookie>); | deref!(SetCookie => Vec<Cookie>); | ||||||
|  |  | ||||||
| impl Header for SetCookie { | impl Header for SetCookie { | ||||||
|     fn header_name(_: Option<SetCookie>) -> &'static str { |     fn header_name() -> &'static str { | ||||||
|         "Set-Cookie" |         "Set-Cookie" | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -22,7 +22,7 @@ pub struct TransferEncoding(pub Vec<Encoding>); | |||||||
| deref!(TransferEncoding => Vec<Encoding>); | deref!(TransferEncoding => Vec<Encoding>); | ||||||
|  |  | ||||||
| impl Header for TransferEncoding { | impl Header for TransferEncoding { | ||||||
|     fn header_name(_: Option<TransferEncoding>) -> &'static str { |     fn header_name() -> &'static str { | ||||||
|         "Transfer-Encoding" |         "Transfer-Encoding" | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -39,7 +39,7 @@ impl fmt::String for Protocol { | |||||||
| } | } | ||||||
|  |  | ||||||
| impl Header for Upgrade { | impl Header for Upgrade { | ||||||
|     fn header_name(_: Option<Upgrade>) -> &'static str { |     fn header_name() -> &'static str { | ||||||
|         "Upgrade" |         "Upgrade" | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -11,7 +11,7 @@ pub struct UserAgent(pub String); | |||||||
| deref!(UserAgent => String); | deref!(UserAgent => String); | ||||||
|  |  | ||||||
| impl Header for UserAgent { | impl Header for UserAgent { | ||||||
|     fn header_name(_: Option<UserAgent>) -> &'static str { |     fn header_name() -> &'static str { | ||||||
|         "User-Agent" |         "User-Agent" | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -15,7 +15,7 @@ pub enum Vary { | |||||||
| } | } | ||||||
|  |  | ||||||
| impl Header for Vary { | impl Header for Vary { | ||||||
|     fn header_name(_: Option<Vary>) -> &'static str { |     fn header_name() -> &'static str { | ||||||
|         "Vary" |         "Vary" | ||||||
|     } |     } | ||||||
|  |  | ||||||
|   | |||||||
| @@ -38,9 +38,8 @@ type HeaderName = UniCase<CowString<'static>>; | |||||||
| pub trait Header: Clone + Any + Send + Sync { | pub trait Header: Clone + Any + Send + Sync { | ||||||
|     /// Returns the name of the header field this belongs to. |     /// Returns the name of the header field this belongs to. | ||||||
|     /// |     /// | ||||||
|     /// The market `Option` is to hint to the type system which implementation |     /// This will become an associated constant once available. | ||||||
|     /// to call. This can be done away with once UFCS arrives. |     fn header_name() -> &'static str; | ||||||
|     fn header_name(marker: Option<Self>) -> &'static str; |  | ||||||
|     /// Parse a header from a raw stream of bytes. |     /// Parse a header from a raw stream of bytes. | ||||||
|     /// |     /// | ||||||
|     /// It's possible that a request can include a header field more than once, |     /// It's possible that a request can include a header field more than once, | ||||||
| @@ -107,8 +106,9 @@ impl Clone for Box<HeaderFormat + Send + Sync> { | |||||||
|     } |     } | ||||||
| } | } | ||||||
|  |  | ||||||
|  | #[inline] | ||||||
| fn header_name<T: Header>() -> &'static str { | fn header_name<T: Header>() -> &'static str { | ||||||
|     let name = Header::header_name(None::<T>); |     let name = <T as Header>::header_name(); | ||||||
|     name |     name | ||||||
| } | } | ||||||
|  |  | ||||||
| @@ -246,7 +246,7 @@ impl Headers { | |||||||
|     /// Removes a header from the map, if one existed. |     /// Removes a header from the map, if one existed. | ||||||
|     /// Returns true if a header has been removed. |     /// Returns true if a header has been removed. | ||||||
|     pub fn remove<H: Header + HeaderFormat>(&mut self) -> bool { |     pub fn remove<H: Header + HeaderFormat>(&mut self) -> bool { | ||||||
|         self.data.remove(&UniCase(Borrowed(Header::header_name(None::<H>)))).is_some() |         self.data.remove(&UniCase(Borrowed(header_name::<H>()))).is_some() | ||||||
|     } |     } | ||||||
|  |  | ||||||
|     /// Returns an iterator over the header fields. |     /// Returns an iterator over the header fields. | ||||||
| @@ -559,7 +559,7 @@ mod tests { | |||||||
|     struct CrazyLength(Option<bool>, usize); |     struct CrazyLength(Option<bool>, usize); | ||||||
|  |  | ||||||
|     impl Header for CrazyLength { |     impl Header for CrazyLength { | ||||||
|         fn header_name(_: Option<CrazyLength>) -> &'static str { |         fn header_name() -> &'static str { | ||||||
|             "content-length" |             "content-length" | ||||||
|         } |         } | ||||||
|         fn parse_header(raw: &[Vec<u8>]) -> Option<CrazyLength> { |         fn parse_header(raw: &[Vec<u8>]) -> Option<CrazyLength> { | ||||||
| @@ -678,7 +678,7 @@ mod tests { | |||||||
|         headers.set(ContentLength(11)); |         headers.set(ContentLength(11)); | ||||||
|         for header in headers.iter() { |         for header in headers.iter() { | ||||||
|             assert!(header.is::<ContentLength>()); |             assert!(header.is::<ContentLength>()); | ||||||
|             assert_eq!(header.name(), Header::header_name(None::<ContentLength>)); |             assert_eq!(header.name(), <ContentLength as Header>::header_name()); | ||||||
|             assert_eq!(header.value(), Some(&ContentLength(11))); |             assert_eq!(header.value(), Some(&ContentLength(11))); | ||||||
|             assert_eq!(header.value_string(), "11".to_string()); |             assert_eq!(header.value_string(), "11".to_string()); | ||||||
|         } |         } | ||||||
|   | |||||||
		Reference in New Issue
	
	Block a user