Skip to content

Commit

Permalink
Implement changes suggested by @seanmonstar
Browse files Browse the repository at this point in the history
  • Loading branch information
lovasoa committed Jul 12, 2019
1 parent f2f91c7 commit b504df7
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 12 deletions.
3 changes: 2 additions & 1 deletion src/convert.rs
@@ -1,5 +1,5 @@
use Error;
use header::{HeaderName, HeaderValue};
use header::{HeaderName, HeaderValue, HeaderMap};
use method::Method;
use sealed::Sealed;
use status::StatusCode;
Expand Down Expand Up @@ -56,6 +56,7 @@ reflexive! {
Uri,
Method,
StatusCode,
HeaderMap,
HeaderName,
HeaderValue,
Scheme,
Expand Down
39 changes: 28 additions & 11 deletions src/header/map.rs
@@ -1,15 +1,16 @@
use super::HeaderValue;
use super::name::{HeaderName, HdrName, InvalidHeaderName};
use convert::{HttpTryFrom, HttpTryInto};
use Error;
use sealed::Sealed;

use std::{fmt, mem, ops, ptr, vec};
use std::collections::{BTreeMap, HashMap};
use std::collections::hash_map::RandomState;
use std::hash::{BuildHasher, Hasher, Hash};
use std::hash::{BuildHasher, Hash, Hasher};
use std::iter::FromIterator;
use std::marker::PhantomData;

use convert::{HttpTryFrom, HttpTryInto};
use Error;

use super::HeaderValue;
use super::name::{HdrName, HeaderName, InvalidHeaderName};

pub use self::as_header_name::AsHeaderName;
pub use self::into_header_name::IntoHeaderName;

Expand Down Expand Up @@ -1724,7 +1725,23 @@ impl<T> FromIterator<(HeaderName, T)> for HeaderMap<T>
}
}

impl<T> Sealed for HeaderMap<T> {}
/// A marker trait that allows conversion from a type to HeaderMap
/// This trait is needed to have both a fast implementation of
/// HttpTryFrom<HeaderMap> and a generic implementation
/// of HttpTryFrom<IntoIterator<Item=(K,V)>> for HeaderMap that do not conflict.
pub trait IntoHeaderMapAllowed {}

impl<K, V, S> IntoHeaderMapAllowed for HashMap<K, V, S> {}

impl<'a, K, V, S> IntoHeaderMapAllowed for &'a HashMap<K, V, S> {}

impl<K, V> IntoHeaderMapAllowed for BTreeMap<K, V> {}

impl<'a, K, V> IntoHeaderMapAllowed for &'a BTreeMap<K, V> {}

impl<'a, T> IntoHeaderMapAllowed for &'a [T] {}

impl<T> IntoHeaderMapAllowed for Vec<T> {}

/// Convert a collection of tuples into a HeaderMap
///
Expand All @@ -1746,7 +1763,7 @@ impl<T> Sealed for HeaderMap<T> {}
/// ```
impl<C, K, V> HttpTryFrom<C> for HeaderMap<HeaderValue>
where
C: IntoIterator<Item=(K, V)>,
C: IntoIterator<Item=(K, V)> + IntoHeaderMapAllowed,
HeaderName: HttpTryFrom<K>,
HeaderValue: HttpTryFrom<V>
{
Expand Down Expand Up @@ -3132,7 +3149,7 @@ mod into_header_name {
use super::{HdrName, HeaderMap, HeaderName};

/// A marker trait used to identify values that can be used as insert keys
/// to a `HeaderMap`.
/// to a `HeaderMap`.
pub trait IntoHeaderName: Sealed {}

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

/// A marker trait used to identify values that can be used as search keys
/// to a `HeaderMap`.
/// to a `HeaderMap`.
pub trait AsHeaderName: Sealed {}

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

0 comments on commit b504df7

Please sign in to comment.