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;
|
||||
|
||||
impl hyper::header::Header for Foo {
|
||||
fn header_name(_: Option<Foo>) -> &'static str {
|
||||
fn header_name() -> &'static str {
|
||||
"x-foo"
|
||||
}
|
||||
fn parse_header(_: &[Vec<u8>]) -> Option<Foo> {
|
||||
|
||||
@@ -50,7 +50,7 @@ impl Writer for MockStream {
|
||||
struct Foo;
|
||||
|
||||
impl hyper::header::Header for Foo {
|
||||
fn header_name(_: Option<Foo>) -> &'static str {
|
||||
fn header_name() -> &'static str {
|
||||
"x-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>>);
|
||||
|
||||
impl header::Header for Accept {
|
||||
fn header_name(_: Option<Accept>) -> &'static str {
|
||||
fn header_name() -> &'static str {
|
||||
"Accept"
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ pub struct AccessControlAllowHeaders(pub Vec<String>);
|
||||
|
||||
impl header::Header for AccessControlAllowHeaders {
|
||||
#[inline]
|
||||
fn header_name(_: Option<AccessControlAllowHeaders>) -> &'static str {
|
||||
fn header_name() -> &'static str {
|
||||
"Access-Control-Allow-Headers"
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ pub struct AccessControlAllowMethods(pub Vec<method::Method>);
|
||||
|
||||
impl header::Header for AccessControlAllowMethods {
|
||||
#[inline]
|
||||
fn header_name(_: Option<AccessControlAllowMethods>) -> &'static str {
|
||||
fn header_name() -> &'static str {
|
||||
"Access-Control-Allow-Methods"
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ pub enum AccessControlAllowOrigin {
|
||||
|
||||
impl header::Header for AccessControlAllowOrigin {
|
||||
#[inline]
|
||||
fn header_name(_: Option<AccessControlAllowOrigin>) -> &'static str {
|
||||
fn header_name() -> &'static str {
|
||||
"Access-Control-Allow-Origin"
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ pub struct AccessControlMaxAge(pub u32);
|
||||
|
||||
impl header::Header for AccessControlMaxAge {
|
||||
#[inline]
|
||||
fn header_name(_: Option<AccessControlMaxAge>) -> &'static str {
|
||||
fn header_name() -> &'static str {
|
||||
"Access-Control-Max-Age"
|
||||
}
|
||||
|
||||
|
||||
@@ -14,7 +14,7 @@ pub struct AccessControlRequestHeaders(pub Vec<String>);
|
||||
|
||||
impl header::Header for AccessControlRequestHeaders {
|
||||
#[inline]
|
||||
fn header_name(_: Option<AccessControlRequestHeaders>) -> &'static str {
|
||||
fn header_name() -> &'static str {
|
||||
"Access-Control-Request-Headers"
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ pub struct AccessControlRequestMethod(pub Method);
|
||||
|
||||
impl header::Header for AccessControlRequestMethod {
|
||||
#[inline]
|
||||
fn header_name(_: Option<AccessControlRequestMethod>) -> &'static str {
|
||||
fn header_name() -> &'static str {
|
||||
"Access-Control-Request-Method"
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ pub struct Allow(pub Vec<Method>);
|
||||
deref!(Allow => Vec<Method>);
|
||||
|
||||
impl Header for Allow {
|
||||
fn header_name(_: Option<Allow>) -> &'static str {
|
||||
fn header_name() -> &'static str {
|
||||
"Allow"
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ impl<S: Scheme> DerefMut for Authorization<S> {
|
||||
}
|
||||
|
||||
impl<S: Scheme> Header for Authorization<S> {
|
||||
fn header_name(_: Option<Authorization<S>>) -> &'static str {
|
||||
fn header_name() -> &'static str {
|
||||
"Authorization"
|
||||
}
|
||||
|
||||
|
||||
@@ -10,7 +10,7 @@ pub struct CacheControl(pub Vec<CacheDirective>);
|
||||
deref!(CacheControl => Vec<CacheDirective>);
|
||||
|
||||
impl Header for CacheControl {
|
||||
fn header_name(_: Option<CacheControl>) -> &'static str {
|
||||
fn header_name() -> &'static str {
|
||||
"Cache-Control"
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ impl fmt::String for ConnectionOption {
|
||||
}
|
||||
|
||||
impl Header for Connection {
|
||||
fn header_name(_: Option<Connection>) -> &'static str {
|
||||
fn header_name() -> &'static str {
|
||||
"Connection"
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ pub struct ContentLength(pub u64);
|
||||
deref!(ContentLength => u64);
|
||||
|
||||
impl Header for ContentLength {
|
||||
fn header_name(_: Option<ContentLength>) -> &'static str {
|
||||
fn header_name() -> &'static str {
|
||||
"Content-Length"
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ pub struct ContentType(pub Mime);
|
||||
deref!(ContentType => Mime);
|
||||
|
||||
impl Header for ContentType {
|
||||
fn header_name(_: Option<ContentType>) -> &'static str {
|
||||
fn header_name() -> &'static str {
|
||||
"Content-Type"
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ pub struct Cookies(pub Vec<Cookie>);
|
||||
deref!(Cookies => Vec<Cookie>);
|
||||
|
||||
impl Header for Cookies {
|
||||
fn header_name(_: Option<Cookies>) -> &'static str {
|
||||
fn header_name() -> &'static str {
|
||||
"Cookie"
|
||||
}
|
||||
|
||||
|
||||
@@ -13,7 +13,7 @@ pub struct Date(pub Tm);
|
||||
deref!(Date => Tm);
|
||||
|
||||
impl Header for Date {
|
||||
fn header_name(_: Option<Date>) -> &'static str {
|
||||
fn header_name() -> &'static str {
|
||||
"Date"
|
||||
}
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ pub struct Etag {
|
||||
}
|
||||
|
||||
impl Header for Etag {
|
||||
fn header_name(_: Option<Etag>) -> &'static str {
|
||||
fn header_name() -> &'static str {
|
||||
"Etag"
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ pub struct Expires(pub Tm);
|
||||
deref!(Expires => Tm);
|
||||
|
||||
impl Header for Expires {
|
||||
fn header_name(_: Option<Expires>) -> &'static str {
|
||||
fn header_name() -> &'static str {
|
||||
"Expires"
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ pub struct Host {
|
||||
}
|
||||
|
||||
impl Header for Host {
|
||||
fn header_name(_: Option<Host>) -> &'static str {
|
||||
fn header_name() -> &'static str {
|
||||
"Host"
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ pub struct IfModifiedSince(pub Tm);
|
||||
deref!(IfModifiedSince => Tm);
|
||||
|
||||
impl Header for IfModifiedSince {
|
||||
fn header_name(_: Option<IfModifiedSince>) -> &'static str {
|
||||
fn header_name() -> &'static str {
|
||||
"If-Modified-Since"
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,7 @@ pub struct LastModified(pub Tm);
|
||||
deref!(LastModified => Tm);
|
||||
|
||||
impl Header for LastModified {
|
||||
fn header_name(_: Option<LastModified>) -> &'static str {
|
||||
fn header_name() -> &'static str {
|
||||
"Last-Modified"
|
||||
}
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ pub struct Location(pub String);
|
||||
deref!(Location => String);
|
||||
|
||||
impl Header for Location {
|
||||
fn header_name(_: Option<Location>) -> &'static str {
|
||||
fn header_name() -> &'static str {
|
||||
"Location"
|
||||
}
|
||||
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ pub struct Referer(pub String);
|
||||
deref!(Referer => String);
|
||||
|
||||
impl Header for Referer {
|
||||
fn header_name(_: Option<Referer>) -> &'static str {
|
||||
fn header_name() -> &'static str {
|
||||
"Referer"
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ pub struct SetCookie(pub Vec<Cookie>);
|
||||
deref!(SetCookie => Vec<Cookie>);
|
||||
|
||||
impl Header for SetCookie {
|
||||
fn header_name(_: Option<SetCookie>) -> &'static str {
|
||||
fn header_name() -> &'static str {
|
||||
"Set-Cookie"
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ pub struct TransferEncoding(pub Vec<Encoding>);
|
||||
deref!(TransferEncoding => Vec<Encoding>);
|
||||
|
||||
impl Header for TransferEncoding {
|
||||
fn header_name(_: Option<TransferEncoding>) -> &'static str {
|
||||
fn header_name() -> &'static str {
|
||||
"Transfer-Encoding"
|
||||
}
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ impl fmt::String for Protocol {
|
||||
}
|
||||
|
||||
impl Header for Upgrade {
|
||||
fn header_name(_: Option<Upgrade>) -> &'static str {
|
||||
fn header_name() -> &'static str {
|
||||
"Upgrade"
|
||||
}
|
||||
|
||||
|
||||
@@ -11,7 +11,7 @@ pub struct UserAgent(pub String);
|
||||
deref!(UserAgent => String);
|
||||
|
||||
impl Header for UserAgent {
|
||||
fn header_name(_: Option<UserAgent>) -> &'static str {
|
||||
fn header_name() -> &'static str {
|
||||
"User-Agent"
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@ pub enum Vary {
|
||||
}
|
||||
|
||||
impl Header for Vary {
|
||||
fn header_name(_: Option<Vary>) -> &'static str {
|
||||
fn header_name() -> &'static str {
|
||||
"Vary"
|
||||
}
|
||||
|
||||
|
||||
@@ -38,9 +38,8 @@ type HeaderName = UniCase<CowString<'static>>;
|
||||
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<Self>) -> &'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<HeaderFormat + Send + Sync> {
|
||||
}
|
||||
}
|
||||
|
||||
#[inline]
|
||||
fn header_name<T: Header>() -> &'static str {
|
||||
let name = Header::header_name(None::<T>);
|
||||
let name = <T as Header>::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<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.
|
||||
@@ -559,7 +559,7 @@ mod tests {
|
||||
struct CrazyLength(Option<bool>, usize);
|
||||
|
||||
impl Header for CrazyLength {
|
||||
fn header_name(_: Option<CrazyLength>) -> &'static str {
|
||||
fn header_name() -> &'static str {
|
||||
"content-length"
|
||||
}
|
||||
fn parse_header(raw: &[Vec<u8>]) -> Option<CrazyLength> {
|
||||
@@ -678,7 +678,7 @@ mod tests {
|
||||
headers.set(ContentLength(11));
|
||||
for header in headers.iter() {
|
||||
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_string(), "11".to_string());
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user