@@ -38,9 +38,8 @@ type HeaderName = UniCase<CowString<'static>>;
38
38
pub trait Header : Clone + Any + Send + Sync {
39
39
/// Returns the name of the header field this belongs to.
40
40
///
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 ;
44
43
/// Parse a header from a raw stream of bytes.
45
44
///
46
45
/// 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> {
107
106
}
108
107
}
109
108
109
+ #[ inline]
110
110
fn header_name < T : Header > ( ) -> & ' static str {
111
- let name = Header :: header_name ( None :: < T > ) ;
111
+ let name = < T as Header > :: header_name ( ) ;
112
112
name
113
113
}
114
114
@@ -246,7 +246,7 @@ impl Headers {
246
246
/// Removes a header from the map, if one existed.
247
247
/// Returns true if a header has been removed.
248
248
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 ( )
250
250
}
251
251
252
252
/// Returns an iterator over the header fields.
@@ -559,7 +559,7 @@ mod tests {
559
559
struct CrazyLength ( Option < bool > , usize ) ;
560
560
561
561
impl Header for CrazyLength {
562
- fn header_name ( _ : Option < CrazyLength > ) -> & ' static str {
562
+ fn header_name ( ) -> & ' static str {
563
563
"content-length"
564
564
}
565
565
fn parse_header ( raw : & [ Vec < u8 > ] ) -> Option < CrazyLength > {
@@ -678,7 +678,7 @@ mod tests {
678
678
headers. set ( ContentLength ( 11 ) ) ;
679
679
for header in headers. iter ( ) {
680
680
assert ! ( header. is:: <ContentLength >( ) ) ;
681
- assert_eq ! ( header. name( ) , Header :: header_name( None :: < ContentLength > ) ) ;
681
+ assert_eq ! ( header. name( ) , < ContentLength as Header > :: header_name( ) ) ;
682
682
assert_eq ! ( header. value( ) , Some ( & ContentLength ( 11 ) ) ) ;
683
683
assert_eq ! ( header. value_string( ) , "11" . to_string( ) ) ;
684
684
}
0 commit comments