@@ -182,6 +182,11 @@ impl Header + Send + Sync {
182
182
unsafe fn downcast_mut_unchecked < T : ' static > ( & mut self ) -> & mut T {
183
183
& mut * ( mem:: transmute :: < * mut _ , ( * mut ( ) , * mut ( ) ) > ( self ) . 0 as * mut T )
184
184
}
185
+
186
+ #[ inline]
187
+ unsafe fn downcast_unchecked < T : ' static > ( self : Box < Self > ) -> T {
188
+ * Box :: from_raw ( mem:: transmute :: < * mut _ , ( * mut ( ) , * mut ( ) ) > ( Box :: into_raw ( self ) ) . 0 as * mut T )
189
+ }
185
190
}
186
191
187
192
impl Clone for Box < Header + Send + Sync > {
@@ -320,10 +325,14 @@ impl Headers {
320
325
}
321
326
322
327
/// Removes a header from the map, if one existed.
323
- /// Returns true if a header has been removed.
324
- pub fn remove < H : Header > ( & mut self ) -> bool {
328
+ /// Returns the header, if one has been removed and could be parsed.
329
+ ///
330
+ /// Note that this function may return `None` even though a header was removed. If you want to
331
+ /// know whether a header exists, rather rely on `has`.
332
+ pub fn remove < H : Header > ( & mut self ) -> Option < H > {
325
333
trace ! ( "Headers.remove( {:?} )" , header_name:: <H >( ) ) ;
326
- self . data . remove ( & HeaderName ( UniCase ( Cow :: Borrowed ( header_name :: < H > ( ) ) ) ) ) . is_some ( )
334
+ self . data . remove ( & HeaderName ( UniCase ( Cow :: Borrowed ( header_name :: < H > ( ) ) ) ) )
335
+ . and_then ( Item :: into_typed :: < H > )
327
336
}
328
337
329
338
/// Returns an iterator over the header fields.
@@ -751,6 +760,13 @@ mod tests {
751
760
assert_eq ! ( headers. get_raw( "Content-length" ) , None ) ;
752
761
}
753
762
763
+ #[ test]
764
+ fn test_remove ( ) {
765
+ let mut headers = Headers :: new ( ) ;
766
+ headers. set ( ContentLength ( 10 ) ) ;
767
+ assert_eq ! ( headers. remove( ) , Some ( ContentLength ( 10 ) ) ) ;
768
+ }
769
+
754
770
#[ test]
755
771
fn test_len ( ) {
756
772
let mut headers = Headers :: new ( ) ;
0 commit comments