1
- use super :: HeaderValue ;
2
- use super :: name:: { HeaderName , HdrName , InvalidHeaderName } ;
3
- use convert:: { HttpTryFrom , HttpTryInto } ;
4
- use Error ;
5
- use sealed:: Sealed ;
6
-
7
1
use std:: { fmt, mem, ops, ptr, vec} ;
2
+ use std:: collections:: { BTreeMap , HashMap } ;
8
3
use std:: collections:: hash_map:: RandomState ;
9
- use std:: hash:: { BuildHasher , Hasher , Hash } ;
4
+ use std:: hash:: { BuildHasher , Hash , Hasher } ;
10
5
use std:: iter:: FromIterator ;
11
6
use std:: marker:: PhantomData ;
12
7
8
+ use convert:: { HttpTryFrom , HttpTryInto } ;
9
+ use Error ;
10
+
11
+ use super :: HeaderValue ;
12
+ use super :: name:: { HdrName , HeaderName , InvalidHeaderName } ;
13
+
13
14
pub use self :: as_header_name:: AsHeaderName ;
14
15
pub use self :: into_header_name:: IntoHeaderName ;
15
16
@@ -1724,7 +1725,23 @@ impl<T> FromIterator<(HeaderName, T)> for HeaderMap<T>
1724
1725
}
1725
1726
}
1726
1727
1727
- impl < T > Sealed for HeaderMap < T > { }
1728
+ /// A marker trait that allows conversion from a type to HeaderMap
1729
+ /// This trait is needed to have both a fast implementation of
1730
+ /// HttpTryFrom<HeaderMap> and a generic implementation
1731
+ /// of HttpTryFrom<IntoIterator<Item=(K,V)>> for HeaderMap that do not conflict.
1732
+ pub trait IntoHeaderMapAllowed { }
1733
+
1734
+ impl < K , V , S > IntoHeaderMapAllowed for HashMap < K , V , S > { }
1735
+
1736
+ impl < ' a , K , V , S > IntoHeaderMapAllowed for & ' a HashMap < K , V , S > { }
1737
+
1738
+ impl < K , V > IntoHeaderMapAllowed for BTreeMap < K , V > { }
1739
+
1740
+ impl < ' a , K , V > IntoHeaderMapAllowed for & ' a BTreeMap < K , V > { }
1741
+
1742
+ impl < ' a , T > IntoHeaderMapAllowed for & ' a [ T ] { }
1743
+
1744
+ impl < T > IntoHeaderMapAllowed for Vec < T > { }
1728
1745
1729
1746
/// Convert a collection of tuples into a HeaderMap
1730
1747
///
@@ -1746,7 +1763,7 @@ impl<T> Sealed for HeaderMap<T> {}
1746
1763
/// ```
1747
1764
impl < C , K , V > HttpTryFrom < C > for HeaderMap < HeaderValue >
1748
1765
where
1749
- C : IntoIterator < Item =( K , V ) > ,
1766
+ C : IntoIterator < Item =( K , V ) > + IntoHeaderMapAllowed ,
1750
1767
HeaderName : HttpTryFrom < K > ,
1751
1768
HeaderValue : HttpTryFrom < V >
1752
1769
{
@@ -3132,7 +3149,7 @@ mod into_header_name {
3132
3149
use super :: { HdrName , HeaderMap , HeaderName } ;
3133
3150
3134
3151
/// A marker trait used to identify values that can be used as insert keys
3135
- /// to a `HeaderMap`.
3152
+ /// to a `HeaderMap`.
3136
3153
pub trait IntoHeaderName : Sealed { }
3137
3154
3138
3155
// All methods are on this pub(super) trait, instead of `IntoHeaderName`,
@@ -3204,7 +3221,7 @@ mod as_header_name {
3204
3221
use super :: { Entry , HdrName , HeaderMap , HeaderName , InvalidHeaderName } ;
3205
3222
3206
3223
/// A marker trait used to identify values that can be used as search keys
3207
- /// to a `HeaderMap`.
3224
+ /// to a `HeaderMap`.
3208
3225
pub trait AsHeaderName : Sealed { }
3209
3226
3210
3227
// All methods are on this pub(super) trait, instead of `AsHeaderName`,
0 commit comments