Skip to content

Commit b504df7

Browse files

File tree

2 files changed

+30
-12
lines changed

2 files changed

+30
-12
lines changed

src/convert.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use Error;
2-
use header::{HeaderName, HeaderValue};
2+
use header::{HeaderName, HeaderValue, HeaderMap};
33
use method::Method;
44
use sealed::Sealed;
55
use status::StatusCode;
@@ -56,6 +56,7 @@ reflexive! {
5656
Uri,
5757
Method,
5858
StatusCode,
59+
HeaderMap,
5960
HeaderName,
6061
HeaderValue,
6162
Scheme,

src/header/map.rs

+28-11
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,16 @@
1-
use super::HeaderValue;
2-
use super::name::{HeaderName, HdrName, InvalidHeaderName};
3-
use convert::{HttpTryFrom, HttpTryInto};
4-
use Error;
5-
use sealed::Sealed;
6-
71
use std::{fmt, mem, ops, ptr, vec};
2+
use std::collections::{BTreeMap, HashMap};
83
use std::collections::hash_map::RandomState;
9-
use std::hash::{BuildHasher, Hasher, Hash};
4+
use std::hash::{BuildHasher, Hash, Hasher};
105
use std::iter::FromIterator;
116
use std::marker::PhantomData;
127

8+
use convert::{HttpTryFrom, HttpTryInto};
9+
use Error;
10+
11+
use super::HeaderValue;
12+
use super::name::{HdrName, HeaderName, InvalidHeaderName};
13+
1314
pub use self::as_header_name::AsHeaderName;
1415
pub use self::into_header_name::IntoHeaderName;
1516

@@ -1724,7 +1725,23 @@ impl<T> FromIterator<(HeaderName, T)> for HeaderMap<T>
17241725
}
17251726
}
17261727

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> {}
17281745

17291746
/// Convert a collection of tuples into a HeaderMap
17301747
///
@@ -1746,7 +1763,7 @@ impl<T> Sealed for HeaderMap<T> {}
17461763
/// ```
17471764
impl<C, K, V> HttpTryFrom<C> for HeaderMap<HeaderValue>
17481765
where
1749-
C: IntoIterator<Item=(K, V)>,
1766+
C: IntoIterator<Item=(K, V)> + IntoHeaderMapAllowed,
17501767
HeaderName: HttpTryFrom<K>,
17511768
HeaderValue: HttpTryFrom<V>
17521769
{
@@ -3132,7 +3149,7 @@ mod into_header_name {
31323149
use super::{HdrName, HeaderMap, HeaderName};
31333150

31343151
/// A marker trait used to identify values that can be used as insert keys
3135-
/// to a `HeaderMap`.
3152+
/// to a `HeaderMap`.
31363153
pub trait IntoHeaderName: Sealed {}
31373154

31383155
// All methods are on this pub(super) trait, instead of `IntoHeaderName`,
@@ -3204,7 +3221,7 @@ mod as_header_name {
32043221
use super::{Entry, HdrName, HeaderMap, HeaderName, InvalidHeaderName};
32053222

32063223
/// A marker trait used to identify values that can be used as search keys
3207-
/// to a `HeaderMap`.
3224+
/// to a `HeaderMap`.
32083225
pub trait AsHeaderName: Sealed {}
32093226

32103227
// All methods are on this pub(super) trait, instead of `AsHeaderName`,

0 commit comments

Comments
 (0)