Skip to content

Commit 8215889

Browse files
committed
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.
1 parent 65ed029 commit 8215889

31 files changed

+38
-38
lines changed

benches/client.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ fn handle(_r: Request, res: Response) {
3434
struct Foo;
3535

3636
impl hyper::header::Header for Foo {
37-
fn header_name(_: Option<Foo>) -> &'static str {
37+
fn header_name() -> &'static str {
3838
"x-foo"
3939
}
4040
fn parse_header(_: &[Vec<u8>]) -> Option<Foo> {

benches/client_mock_tcp.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl Writer for MockStream {
5050
struct Foo;
5151

5252
impl hyper::header::Header for Foo {
53-
fn header_name(_: Option<Foo>) -> &'static str {
53+
fn header_name() -> &'static str {
5454
"x-foo"
5555
}
5656
fn parse_header(_: &[Vec<u8>]) -> Option<Foo> {

src/header/common/accept.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub struct Accept(pub Vec<header::QualityItem<mime::Mime>>);
3131
deref!(Accept => Vec<header::QualityItem<mime::Mime>>);
3232

3333
impl header::Header for Accept {
34-
fn header_name(_: Option<Accept>) -> &'static str {
34+
fn header_name() -> &'static str {
3535
"Accept"
3636
}
3737

src/header/common/access_control/allow_headers.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub struct AccessControlAllowHeaders(pub Vec<String>);
1515

1616
impl header::Header for AccessControlAllowHeaders {
1717
#[inline]
18-
fn header_name(_: Option<AccessControlAllowHeaders>) -> &'static str {
18+
fn header_name() -> &'static str {
1919
"Access-Control-Allow-Headers"
2020
}
2121

src/header/common/access_control/allow_methods.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub struct AccessControlAllowMethods(pub Vec<method::Method>);
1616

1717
impl header::Header for AccessControlAllowMethods {
1818
#[inline]
19-
fn header_name(_: Option<AccessControlAllowMethods>) -> &'static str {
19+
fn header_name() -> &'static str {
2020
"Access-Control-Allow-Methods"
2121
}
2222

src/header/common/access_control/allow_origin.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ pub enum AccessControlAllowOrigin {
2323

2424
impl header::Header for AccessControlAllowOrigin {
2525
#[inline]
26-
fn header_name(_: Option<AccessControlAllowOrigin>) -> &'static str {
26+
fn header_name() -> &'static str {
2727
"Access-Control-Allow-Origin"
2828
}
2929

src/header/common/access_control/max_age.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub struct AccessControlMaxAge(pub u32);
1414

1515
impl header::Header for AccessControlMaxAge {
1616
#[inline]
17-
fn header_name(_: Option<AccessControlMaxAge>) -> &'static str {
17+
fn header_name() -> &'static str {
1818
"Access-Control-Max-Age"
1919
}
2020

src/header/common/access_control/request_headers.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ pub struct AccessControlRequestHeaders(pub Vec<String>);
1414

1515
impl header::Header for AccessControlRequestHeaders {
1616
#[inline]
17-
fn header_name(_: Option<AccessControlRequestHeaders>) -> &'static str {
17+
fn header_name() -> &'static str {
1818
"Access-Control-Request-Headers"
1919
}
2020

src/header/common/access_control/request_method.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub struct AccessControlRequestMethod(pub Method);
1515

1616
impl header::Header for AccessControlRequestMethod {
1717
#[inline]
18-
fn header_name(_: Option<AccessControlRequestMethod>) -> &'static str {
18+
fn header_name() -> &'static str {
1919
"Access-Control-Request-Method"
2020
}
2121

src/header/common/allow.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub struct Allow(pub Vec<Method>);
1212
deref!(Allow => Vec<Method>);
1313

1414
impl Header for Allow {
15-
fn header_name(_: Option<Allow>) -> &'static str {
15+
fn header_name() -> &'static str {
1616
"Allow"
1717
}
1818

src/header/common/authorization.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ impl<S: Scheme> DerefMut for Authorization<S> {
2323
}
2424

2525
impl<S: Scheme> Header for Authorization<S> {
26-
fn header_name(_: Option<Authorization<S>>) -> &'static str {
26+
fn header_name() -> &'static str {
2727
"Authorization"
2828
}
2929

src/header/common/cache_control.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ pub struct CacheControl(pub Vec<CacheDirective>);
1010
deref!(CacheControl => Vec<CacheDirective>);
1111

1212
impl Header for CacheControl {
13-
fn header_name(_: Option<CacheControl>) -> &'static str {
13+
fn header_name() -> &'static str {
1414
"Cache-Control"
1515
}
1616

src/header/common/connection.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ impl fmt::String for ConnectionOption {
5050
}
5151

5252
impl Header for Connection {
53-
fn header_name(_: Option<Connection>) -> &'static str {
53+
fn header_name() -> &'static str {
5454
"Connection"
5555
}
5656

src/header/common/content_length.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub struct ContentLength(pub u64);
1212
deref!(ContentLength => u64);
1313

1414
impl Header for ContentLength {
15-
fn header_name(_: Option<ContentLength>) -> &'static str {
15+
fn header_name() -> &'static str {
1616
"Content-Length"
1717
}
1818

src/header/common/content_type.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub struct ContentType(pub Mime);
1313
deref!(ContentType => Mime);
1414

1515
impl Header for ContentType {
16-
fn header_name(_: Option<ContentType>) -> &'static str {
16+
fn header_name() -> &'static str {
1717
"Content-Type"
1818
}
1919

src/header/common/cookie.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub struct Cookies(pub Vec<Cookie>);
1919
deref!(Cookies => Vec<Cookie>);
2020

2121
impl Header for Cookies {
22-
fn header_name(_: Option<Cookies>) -> &'static str {
22+
fn header_name() -> &'static str {
2323
"Cookie"
2424
}
2525

src/header/common/date.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ pub struct Date(pub Tm);
1313
deref!(Date => Tm);
1414

1515
impl Header for Date {
16-
fn header_name(_: Option<Date>) -> &'static str {
16+
fn header_name() -> &'static str {
1717
"Date"
1818
}
1919

src/header/common/etag.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ pub struct Etag {
1717
}
1818

1919
impl Header for Etag {
20-
fn header_name(_: Option<Etag>) -> &'static str {
20+
fn header_name() -> &'static str {
2121
"Etag"
2222
}
2323

src/header/common/expires.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub struct Expires(pub Tm);
1212
deref!(Expires => Tm);
1313

1414
impl Header for Expires {
15-
fn header_name(_: Option<Expires>) -> &'static str {
15+
fn header_name() -> &'static str {
1616
"Expires"
1717
}
1818

src/header/common/host.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub struct Host {
1919
}
2020

2121
impl Header for Host {
22-
fn header_name(_: Option<Host>) -> &'static str {
22+
fn header_name() -> &'static str {
2323
"Host"
2424
}
2525

src/header/common/if_modified_since.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub struct IfModifiedSince(pub Tm);
1212
deref!(IfModifiedSince => Tm);
1313

1414
impl Header for IfModifiedSince {
15-
fn header_name(_: Option<IfModifiedSince>) -> &'static str {
15+
fn header_name() -> &'static str {
1616
"If-Modified-Since"
1717
}
1818

src/header/common/last_modified.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ pub struct LastModified(pub Tm);
1212
deref!(LastModified => Tm);
1313

1414
impl Header for LastModified {
15-
fn header_name(_: Option<LastModified>) -> &'static str {
15+
fn header_name() -> &'static str {
1616
"Last-Modified"
1717
}
1818

src/header/common/location.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ pub struct Location(pub String);
1919
deref!(Location => String);
2020

2121
impl Header for Location {
22-
fn header_name(_: Option<Location>) -> &'static str {
22+
fn header_name() -> &'static str {
2323
"Location"
2424
}
2525

src/header/common/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ macro_rules! impl_list_header(
8686
deref!($from => $item);
8787

8888
impl header::Header for $from {
89-
fn header_name(_: Option<$from>) -> &'static str {
89+
fn header_name() -> &'static str {
9090
$name
9191
}
9292

@@ -116,7 +116,7 @@ macro_rules! impl_header(
116116
deref!($from => $item);
117117

118118
impl header::Header for $from {
119-
fn header_name(_: Option<$from>) -> &'static str {
119+
fn header_name() -> &'static str {
120120
$name
121121
}
122122

src/header/common/referer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub struct Referer(pub String);
1616
deref!(Referer => String);
1717

1818
impl Header for Referer {
19-
fn header_name(_: Option<Referer>) -> &'static str {
19+
fn header_name() -> &'static str {
2020
"Referer"
2121
}
2222

src/header/common/set_cookie.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ pub struct SetCookie(pub Vec<Cookie>);
1616
deref!(SetCookie => Vec<Cookie>);
1717

1818
impl Header for SetCookie {
19-
fn header_name(_: Option<SetCookie>) -> &'static str {
19+
fn header_name() -> &'static str {
2020
"Set-Cookie"
2121
}
2222

src/header/common/transfer_encoding.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ pub struct TransferEncoding(pub Vec<Encoding>);
2222
deref!(TransferEncoding => Vec<Encoding>);
2323

2424
impl Header for TransferEncoding {
25-
fn header_name(_: Option<TransferEncoding>) -> &'static str {
25+
fn header_name() -> &'static str {
2626
"Transfer-Encoding"
2727
}
2828

src/header/common/upgrade.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ impl fmt::String for Protocol {
3939
}
4040

4141
impl Header for Upgrade {
42-
fn header_name(_: Option<Upgrade>) -> &'static str {
42+
fn header_name() -> &'static str {
4343
"Upgrade"
4444
}
4545

src/header/common/user_agent.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ pub struct UserAgent(pub String);
1111
deref!(UserAgent => String);
1212

1313
impl Header for UserAgent {
14-
fn header_name(_: Option<UserAgent>) -> &'static str {
14+
fn header_name() -> &'static str {
1515
"User-Agent"
1616
}
1717

src/header/common/vary.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ pub enum Vary {
1515
}
1616

1717
impl Header for Vary {
18-
fn header_name(_: Option<Vary>) -> &'static str {
18+
fn header_name() -> &'static str {
1919
"Vary"
2020
}
2121

src/header/mod.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,8 @@ type HeaderName = UniCase<CowString<'static>>;
3838
pub trait Header: Clone + Any + Send + Sync {
3939
/// Returns the name of the header field this belongs to.
4040
///
41-
/// The market `Option` is to hint to the type system which implementation
42-
/// to call. This can be done away with once UFCS arrives.
43-
fn header_name(marker: Option<Self>) -> &'static str;
41+
/// This will become an associated constant once available.
42+
fn header_name() -> &'static str;
4443
/// Parse a header from a raw stream of bytes.
4544
///
4645
/// 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> {
107106
}
108107
}
109108

109+
#[inline]
110110
fn header_name<T: Header>() -> &'static str {
111-
let name = Header::header_name(None::<T>);
111+
let name = <T as Header>::header_name();
112112
name
113113
}
114114

@@ -246,7 +246,7 @@ impl Headers {
246246
/// Removes a header from the map, if one existed.
247247
/// Returns true if a header has been removed.
248248
pub fn remove<H: Header + HeaderFormat>(&mut self) -> bool {
249-
self.data.remove(&UniCase(Borrowed(Header::header_name(None::<H>)))).is_some()
249+
self.data.remove(&UniCase(Borrowed(header_name::<H>()))).is_some()
250250
}
251251

252252
/// Returns an iterator over the header fields.
@@ -559,7 +559,7 @@ mod tests {
559559
struct CrazyLength(Option<bool>, usize);
560560

561561
impl Header for CrazyLength {
562-
fn header_name(_: Option<CrazyLength>) -> &'static str {
562+
fn header_name() -> &'static str {
563563
"content-length"
564564
}
565565
fn parse_header(raw: &[Vec<u8>]) -> Option<CrazyLength> {
@@ -678,7 +678,7 @@ mod tests {
678678
headers.set(ContentLength(11));
679679
for header in headers.iter() {
680680
assert!(header.is::<ContentLength>());
681-
assert_eq!(header.name(), Header::header_name(None::<ContentLength>));
681+
assert_eq!(header.name(), <ContentLength as Header>::header_name());
682682
assert_eq!(header.value(), Some(&ContentLength(11)));
683683
assert_eq!(header.value_string(), "11".to_string());
684684
}

0 commit comments

Comments
 (0)