Struct HeaderMap
pub struct HeaderMap<T = HeaderValue> {
mask: u16,
indices: Box<[Pos]>,
entries: Vec<Bucket<T>>,
extra_values: Vec<ExtraValue<T>>,
danger: Danger,
}Expand description
A specialized multimap for header names and values.
ยงOverview
HeaderMap is designed specifically for efficient manipulation of HTTP
headers. It supports multiple values per header name and provides
specialized APIs for insertion, retrieval, and iteration.
The internal implementation is optimized for common usage patterns in HTTP, and may change across versions. For example, the current implementation uses Robin Hood hashing to store entries compactly and enable high load factors with good performance. However, the collision resolution strategy and storage mechanism are not part of the public API and may be altered in future releases.
ยงIteration order
Unless otherwise specified, the order in which items are returned by
iterators from HeaderMap methods is arbitrary; there is no guaranteed
ordering among the elements yielded by such an iterator. Changes to the
iteration order are not considered breaking changes, so users must not rely
on any incidental order produced by such an iterator. However, for a given
crate version, the iteration order will be consistent across all platforms.
ยงAdaptive hashing
HeaderMap uses an adaptive strategy for hashing to maintain fast lookups
while resisting hash collision attacks. The default hash function
prioritizes performance. In scenarios where high collision rates are
detectedโtypically indicative of denial-of-service attacksโthe
implementation switches to a more secure, collision-resistant hash function.
ยงLimitations
A HeaderMap can store at most 32,768 entries (header name/value pairs).
Attempting to exceed this limit will result in a panic.
ยงExamples
Basic usage
let mut headers = HeaderMap::new();
headers.insert(HOST, "example.com".parse().unwrap());
headers.insert(CONTENT_LENGTH, "123".parse().unwrap());
assert!(headers.contains_key(HOST));
assert!(!headers.contains_key(LOCATION));
assert_eq!(headers[HOST], "example.com");
headers.remove(HOST);
assert!(!headers.contains_key(HOST));Fieldsยง
ยงmask: u16ยงindices: Box<[Pos]>ยงentries: Vec<Bucket<T>>ยงextra_values: Vec<ExtraValue<T>>ยงdanger: DangerImplementationsยง
ยงimpl<T> HeaderMap<T>
impl<T> HeaderMap<T>
pub fn with_capacity(capacity: usize) -> HeaderMap<T>
pub fn with_capacity(capacity: usize) -> HeaderMap<T>
Create an empty HeaderMap with the specified capacity.
The returned map will allocate internal storage in order to hold about
capacity elements without reallocating. However, this is a โbest
effortโ as there are usage patterns that could cause additional
allocations before capacity headers are stored in the map.
More capacity than requested may be allocated.
ยงPanics
This method panics if capacity exceeds max HeaderMap capacity.
ยงExamples
let map: HeaderMap<u32> = HeaderMap::with_capacity(10);
assert!(map.is_empty());
assert_eq!(12, map.capacity());pub fn try_with_capacity(
capacity: usize,
) -> Result<HeaderMap<T>, MaxSizeReached>
pub fn try_with_capacity( capacity: usize, ) -> Result<HeaderMap<T>, MaxSizeReached>
Create an empty HeaderMap with the specified capacity.
The returned map will allocate internal storage in order to hold about
capacity elements without reallocating. However, this is a โbest
effortโ as there are usage patterns that could cause additional
allocations before capacity headers are stored in the map.
More capacity than requested may be allocated.
ยงErrors
This function may return an error if HeaderMap exceeds max capacity
ยงExamples
let map: HeaderMap<u32> = HeaderMap::try_with_capacity(10).unwrap();
assert!(map.is_empty());
assert_eq!(12, map.capacity());pub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of headers stored in the map.
This number represents the total number of values stored in the map. This number can be greater than or equal to the number of keys stored given that a single key may have more than one associated value.
ยงExamples
let mut map = HeaderMap::new();
assert_eq!(0, map.len());
map.insert(ACCEPT, "text/plain".parse().unwrap());
map.insert(HOST, "localhost".parse().unwrap());
assert_eq!(2, map.len());
map.append(ACCEPT, "text/html".parse().unwrap());
assert_eq!(3, map.len());pub fn keys_len(&self) -> usize
pub fn keys_len(&self) -> usize
Returns the number of keys stored in the map.
This number will be less than or equal to len() as each key may have
more than one associated value.
ยงExamples
let mut map = HeaderMap::new();
assert_eq!(0, map.keys_len());
map.insert(ACCEPT, "text/plain".parse().unwrap());
map.insert(HOST, "localhost".parse().unwrap());
assert_eq!(2, map.keys_len());
map.insert(ACCEPT, "text/html".parse().unwrap());
assert_eq!(2, map.keys_len());pub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns true if the map contains no elements.
ยงExamples
let mut map = HeaderMap::new();
assert!(map.is_empty());
map.insert(HOST, "hello.world".parse().unwrap());
assert!(!map.is_empty());pub fn clear(&mut self)
pub fn clear(&mut self)
Clears the map, removing all key-value pairs. Keeps the allocated memory for reuse.
ยงExamples
let mut map = HeaderMap::new();
map.insert(HOST, "hello.world".parse().unwrap());
map.clear();
assert!(map.is_empty());
assert!(map.capacity() > 0);pub fn capacity(&self) -> usize
pub fn capacity(&self) -> usize
Returns the number of headers the map can hold without reallocating.
This number is an approximation as certain usage patterns could cause additional allocations before the returned capacity is filled.
ยงExamples
let mut map = HeaderMap::new();
assert_eq!(0, map.capacity());
map.insert(HOST, "hello.world".parse().unwrap());
assert_eq!(6, map.capacity());pub fn reserve(&mut self, additional: usize)
pub fn reserve(&mut self, additional: usize)
Reserves capacity for at least additional more headers to be inserted
into the HeaderMap.
The header map may reserve more space to avoid frequent reallocations.
Like with with_capacity, this will be a โbest effortโ to avoid
allocations until additional more headers are inserted. Certain usage
patterns could cause additional allocations before the number is
reached.
ยงPanics
Panics if the new allocation size overflows HeaderMap MAX_SIZE.
ยงExamples
let mut map = HeaderMap::new();
map.reserve(10);pub fn try_reserve(&mut self, additional: usize) -> Result<(), MaxSizeReached>
pub fn try_reserve(&mut self, additional: usize) -> Result<(), MaxSizeReached>
Reserves capacity for at least additional more headers to be inserted
into the HeaderMap.
The header map may reserve more space to avoid frequent reallocations.
Like with with_capacity, this will be a โbest effortโ to avoid
allocations until additional more headers are inserted. Certain usage
patterns could cause additional allocations before the number is
reached.
ยงErrors
This method differs from reserve by returning an error instead of
panicking if the value is too large.
ยงExamples
let mut map = HeaderMap::new();
map.try_reserve(10).unwrap();pub fn get<K>(&self, key: K) -> Option<&T>where
K: AsHeaderName,
pub fn get<K>(&self, key: K) -> Option<&T>where
K: AsHeaderName,
Returns a reference to the value associated with the key.
If there are multiple values associated with the key, then the first one
is returned. Use get_all to get all values associated with a given
key. Returns None if there are no values associated with the key.
ยงExamples
let mut map = HeaderMap::new();
assert!(map.get("host").is_none());
map.insert(HOST, "hello".parse().unwrap());
assert_eq!(map.get(HOST).unwrap(), &"hello");
assert_eq!(map.get("host").unwrap(), &"hello");
map.append(HOST, "world".parse().unwrap());
assert_eq!(map.get("host").unwrap(), &"hello");pub fn get_mut<K>(&mut self, key: K) -> Option<&mut T>where
K: AsHeaderName,
pub fn get_mut<K>(&mut self, key: K) -> Option<&mut T>where
K: AsHeaderName,
Returns a mutable reference to the value associated with the key.
If there are multiple values associated with the key, then the first one
is returned. Use entry to get all values associated with a given
key. Returns None if there are no values associated with the key.
ยงExamples
let mut map = HeaderMap::default();
map.insert(HOST, "hello".to_string());
map.get_mut("host").unwrap().push_str("-world");
assert_eq!(map.get(HOST).unwrap(), &"hello-world");pub fn get_all<K>(&self, key: K) -> GetAll<'_, T>where
K: AsHeaderName,
pub fn get_all<K>(&self, key: K) -> GetAll<'_, T>where
K: AsHeaderName,
Returns a view of all values associated with a key.
The returned view does not incur any allocations and allows iterating
the values associated with the key. See GetAll for more details.
Returns None if there are no values associated with the key.
ยงExamples
let mut map = HeaderMap::new();
map.insert(HOST, "hello".parse().unwrap());
map.append(HOST, "goodbye".parse().unwrap());
let view = map.get_all("host");
let mut iter = view.iter();
assert_eq!(&"hello", iter.next().unwrap());
assert_eq!(&"goodbye", iter.next().unwrap());
assert!(iter.next().is_none());pub fn contains_key<K>(&self, key: K) -> boolwhere
K: AsHeaderName,
pub fn contains_key<K>(&self, key: K) -> boolwhere
K: AsHeaderName,
Returns true if the map contains a value for the specified key.
ยงExamples
let mut map = HeaderMap::new();
assert!(!map.contains_key(HOST));
map.insert(HOST, "world".parse().unwrap());
assert!(map.contains_key("host"));pub fn iter(&self) -> Iter<'_, T> โ
pub fn iter(&self) -> Iter<'_, T> โ
An iterator visiting all key-value pairs.
The iteration order is arbitrary, but consistent across platforms for the same crate version. Each key will be yielded once per associated value. So, if a key has 3 associated values, it will be yielded 3 times.
ยงExamples
let mut map = HeaderMap::new();
map.insert(HOST, "hello".parse().unwrap());
map.append(HOST, "goodbye".parse().unwrap());
map.insert(CONTENT_LENGTH, "123".parse().unwrap());
for (key, value) in map.iter() {
println!("{:?}: {:?}", key, value);
}pub fn iter_mut(&mut self) -> IterMut<'_, T> โ
pub fn iter_mut(&mut self) -> IterMut<'_, T> โ
An iterator visiting all key-value pairs, with mutable value references.
The iterator order is arbitrary, but consistent across platforms for the same crate version. Each key will be yielded once per associated value, so if a key has 3 associated values, it will be yielded 3 times.
ยงExamples
let mut map = HeaderMap::default();
map.insert(HOST, "hello".to_string());
map.append(HOST, "goodbye".to_string());
map.insert(CONTENT_LENGTH, "123".to_string());
for (key, value) in map.iter_mut() {
value.push_str("-boop");
}pub fn keys(&self) -> Keys<'_, T> โ
pub fn keys(&self) -> Keys<'_, T> โ
An iterator visiting all keys.
The iteration order is arbitrary, but consistent across platforms for the same crate version. Each key will be yielded only once even if it has multiple associated values.
ยงExamples
let mut map = HeaderMap::new();
map.insert(HOST, "hello".parse().unwrap());
map.append(HOST, "goodbye".parse().unwrap());
map.insert(CONTENT_LENGTH, "123".parse().unwrap());
for key in map.keys() {
println!("{:?}", key);
}pub fn values(&self) -> Values<'_, T> โ
pub fn values(&self) -> Values<'_, T> โ
An iterator visiting all values.
The iteration order is arbitrary, but consistent across platforms for the same crate version.
ยงExamples
let mut map = HeaderMap::new();
map.insert(HOST, "hello".parse().unwrap());
map.append(HOST, "goodbye".parse().unwrap());
map.insert(CONTENT_LENGTH, "123".parse().unwrap());
for value in map.values() {
println!("{:?}", value);
}pub fn values_mut(&mut self) -> ValuesMut<'_, T> โ
pub fn values_mut(&mut self) -> ValuesMut<'_, T> โ
An iterator visiting all values mutably.
The iteration order is arbitrary, but consistent across platforms for the same crate version.
ยงExamples
let mut map = HeaderMap::default();
map.insert(HOST, "hello".to_string());
map.append(HOST, "goodbye".to_string());
map.insert(CONTENT_LENGTH, "123".to_string());
for value in map.values_mut() {
value.push_str("-boop");
}pub fn drain(&mut self) -> Drain<'_, T> โ
pub fn drain(&mut self) -> Drain<'_, T> โ
Clears the map, returning all entries as an iterator.
The internal memory is kept for reuse.
For each yielded item that has None provided for the HeaderName,
then the associated header name is the same as that of the previously
yielded item. The first yielded item will have HeaderName set.
ยงExamples
let mut map = HeaderMap::new();
map.insert(HOST, "hello".parse().unwrap());
map.append(HOST, "goodbye".parse().unwrap());
map.insert(CONTENT_LENGTH, "123".parse().unwrap());
let mut drain = map.drain();
assert_eq!(drain.next(), Some((Some(HOST), "hello".parse().unwrap())));
assert_eq!(drain.next(), Some((None, "goodbye".parse().unwrap())));
assert_eq!(drain.next(), Some((Some(CONTENT_LENGTH), "123".parse().unwrap())));
assert_eq!(drain.next(), None);pub fn entry<K>(&mut self, key: K) -> Entry<'_, T>where
K: IntoHeaderName,
pub fn entry<K>(&mut self, key: K) -> Entry<'_, T>where
K: IntoHeaderName,
Gets the given keyโs corresponding entry in the map for in-place manipulation.
ยงPanics
This method panics if capacity exceeds max HeaderMap capacity
ยงExamples
let mut map: HeaderMap<u32> = HeaderMap::default();
let headers = &[
"content-length",
"x-hello",
"Content-Length",
"x-world",
];
for &header in headers {
let counter = map.entry(header).or_insert(0);
*counter += 1;
}
assert_eq!(map["content-length"], 2);
assert_eq!(map["x-hello"], 1);pub fn try_entry<K>(
&mut self,
key: K,
) -> Result<Entry<'_, T>, InvalidHeaderName>where
K: AsHeaderName,
pub fn try_entry<K>(
&mut self,
key: K,
) -> Result<Entry<'_, T>, InvalidHeaderName>where
K: AsHeaderName,
Gets the given keyโs corresponding entry in the map for in-place manipulation.
ยงErrors
This method differs from entry by allowing types that may not be
valid HeaderNames to passed as the key (such as String). If they
do not parse as a valid HeaderName, this returns an
InvalidHeaderName error.
If reserving space goes over the maximum, this will also return an
error. However, to prevent breaking changes to the return type, the
error will still say InvalidHeaderName, unlike other try_* methods
which return a MaxSizeReached error.
pub fn insert<K>(&mut self, key: K, val: T) -> Option<T>where
K: IntoHeaderName,
pub fn insert<K>(&mut self, key: K, val: T) -> Option<T>where
K: IntoHeaderName,
Inserts a key-value pair into the map.
If the map did not previously have this key present, then None is
returned.
If the map did have this key present, the new value is associated with
the key and all previous values are removed. Note that only a single
one of the previous values is returned. If there are multiple values
that have been previously associated with the key, then the first one is
returned. See insert_mult on OccupiedEntry for an API that returns
all values.
The key is not updated, though; this matters for types that can be ==
without being identical.
ยงPanics
This method panics if capacity exceeds max HeaderMap capacity
ยงExamples
let mut map = HeaderMap::new();
assert!(map.insert(HOST, "world".parse().unwrap()).is_none());
assert!(!map.is_empty());
let mut prev = map.insert(HOST, "earth".parse().unwrap()).unwrap();
assert_eq!("world", prev);pub fn try_insert<K>(
&mut self,
key: K,
val: T,
) -> Result<Option<T>, MaxSizeReached>where
K: IntoHeaderName,
pub fn try_insert<K>(
&mut self,
key: K,
val: T,
) -> Result<Option<T>, MaxSizeReached>where
K: IntoHeaderName,
Inserts a key-value pair into the map.
If the map did not previously have this key present, then None is
returned.
If the map did have this key present, the new value is associated with
the key and all previous values are removed. Note that only a single
one of the previous values is returned. If there are multiple values
that have been previously associated with the key, then the first one is
returned. See insert_mult on OccupiedEntry for an API that returns
all values.
The key is not updated, though; this matters for types that can be ==
without being identical.
ยงErrors
This function may return an error if HeaderMap exceeds max capacity
ยงExamples
let mut map = HeaderMap::new();
assert!(map.try_insert(HOST, "world".parse().unwrap()).unwrap().is_none());
assert!(!map.is_empty());
let mut prev = map.try_insert(HOST, "earth".parse().unwrap()).unwrap().unwrap();
assert_eq!("world", prev);pub fn append<K>(&mut self, key: K, value: T) -> boolwhere
K: IntoHeaderName,
pub fn append<K>(&mut self, key: K, value: T) -> boolwhere
K: IntoHeaderName,
Inserts a key-value pair into the map.
If the map did not previously have this key present, then false is
returned.
If the map did have this key present, the new value is pushed to the end
of the list of values currently associated with the key. The key is not
updated, though; this matters for types that can be == without being
identical.
ยงPanics
This method panics if capacity exceeds max HeaderMap capacity
ยงExamples
let mut map = HeaderMap::new();
assert!(map.insert(HOST, "world".parse().unwrap()).is_none());
assert!(!map.is_empty());
map.append(HOST, "earth".parse().unwrap());
let values = map.get_all("host");
let mut i = values.iter();
assert_eq!("world", *i.next().unwrap());
assert_eq!("earth", *i.next().unwrap());pub fn try_append<K>(
&mut self,
key: K,
value: T,
) -> Result<bool, MaxSizeReached>where
K: IntoHeaderName,
pub fn try_append<K>(
&mut self,
key: K,
value: T,
) -> Result<bool, MaxSizeReached>where
K: IntoHeaderName,
Inserts a key-value pair into the map.
If the map did not previously have this key present, then false is
returned.
If the map did have this key present, the new value is pushed to the end
of the list of values currently associated with the key. The key is not
updated, though; this matters for types that can be == without being
identical.
ยงErrors
This function may return an error if HeaderMap exceeds max capacity
ยงExamples
let mut map = HeaderMap::new();
assert!(map.try_insert(HOST, "world".parse().unwrap()).unwrap().is_none());
assert!(!map.is_empty());
map.try_append(HOST, "earth".parse().unwrap()).unwrap();
let values = map.get_all("host");
let mut i = values.iter();
assert_eq!("world", *i.next().unwrap());
assert_eq!("earth", *i.next().unwrap());pub fn remove<K>(&mut self, key: K) -> Option<T>where
K: AsHeaderName,
pub fn remove<K>(&mut self, key: K) -> Option<T>where
K: AsHeaderName,
Removes a key from the map, returning the value associated with the key.
Returns None if the map does not contain the key. If there are
multiple values associated with the key, then the first one is returned.
See remove_entry_mult on OccupiedEntry for an API that yields all
values.
ยงExamples
let mut map = HeaderMap::new();
map.insert(HOST, "hello.world".parse().unwrap());
let prev = map.remove(HOST).unwrap();
assert_eq!("hello.world", prev);
assert!(map.remove(HOST).is_none());Trait Implementationsยง
ยงimpl<T> Extend<(HeaderName, T)> for HeaderMap<T>
impl<T> Extend<(HeaderName, T)> for HeaderMap<T>
ยงfn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = (HeaderName, T)>,
fn extend<I>(&mut self, iter: I)where
I: IntoIterator<Item = (HeaderName, T)>,
Sourceยงfn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Sourceยงfn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)ยงimpl<T> Extend<(Option<HeaderName>, T)> for HeaderMap<T>
impl<T> Extend<(Option<HeaderName>, T)> for HeaderMap<T>
ยงfn extend<I>(&mut self, iter: I)
fn extend<I>(&mut self, iter: I)
Extend a HeaderMap with the contents of another HeaderMap.
This function expects the yielded items to follow the same structure as
IntoIter.
ยงPanics
This panics if the first yielded item does not have a HeaderName.
ยงExamples
let mut map = HeaderMap::new();
map.insert(ACCEPT, "text/plain".parse().unwrap());
map.insert(HOST, "hello.world".parse().unwrap());
let mut extra = HeaderMap::new();
extra.insert(HOST, "foo.bar".parse().unwrap());
extra.insert(COOKIE, "hello".parse().unwrap());
extra.append(COOKIE, "world".parse().unwrap());
map.extend(extra);
assert_eq!(map["host"], "foo.bar");
assert_eq!(map["accept"], "text/plain");
assert_eq!(map["cookie"], "hello");
let v = map.get_all("host");
assert_eq!(1, v.iter().count());
let v = map.get_all("cookie");
assert_eq!(2, v.iter().count());Sourceยงfn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one)Sourceยงfn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one)ยงimpl<T> FromIterator<(HeaderName, T)> for HeaderMap<T>
impl<T> FromIterator<(HeaderName, T)> for HeaderMap<T>
ยงfn from_iter<I>(iter: I) -> HeaderMap<T>where
I: IntoIterator<Item = (HeaderName, T)>,
fn from_iter<I>(iter: I) -> HeaderMap<T>where
I: IntoIterator<Item = (HeaderName, T)>,
ยงimpl<S> FromRequestParts<S> for HeaderMap
Clone the headers from the request.
impl<S> FromRequestParts<S> for HeaderMap
Clone the headers from the request.
Prefer using TypedHeader to extract only the headers you need.
ยงtype Rejection = Infallible
type Rejection = Infallible
ยงasync fn from_request_parts(
parts: &mut Parts,
_: &S,
) -> Result<HeaderMap, <HeaderMap as FromRequestParts<S>>::Rejection>
async fn from_request_parts( parts: &mut Parts, _: &S, ) -> Result<HeaderMap, <HeaderMap as FromRequestParts<S>>::Rejection>
ยงimpl<K, T> Index<K> for HeaderMap<T>where
K: AsHeaderName,
impl<K, T> Index<K> for HeaderMap<T>where
K: AsHeaderName,
ยงimpl<'a, T> IntoIterator for &'a HeaderMap<T>
impl<'a, T> IntoIterator for &'a HeaderMap<T>
ยงimpl<'a, T> IntoIterator for &'a mut HeaderMap<T>
impl<'a, T> IntoIterator for &'a mut HeaderMap<T>
ยงimpl<T> IntoIterator for HeaderMap<T>
impl<T> IntoIterator for HeaderMap<T>
ยงfn into_iter(self) -> IntoIter<T> โ
fn into_iter(self) -> IntoIter<T> โ
Creates a consuming iterator, that is, one that moves keys and values out of the map in arbitrary order. The map cannot be used after calling this.
For each yielded item that has None provided for the HeaderName,
then the associated header name is the same as that of the previously
yielded item. The first yielded item will have HeaderName set.
ยงExamples
Basic usage.
let mut map = HeaderMap::new();
map.insert(header::CONTENT_LENGTH, "123".parse().unwrap());
map.insert(header::CONTENT_TYPE, "json".parse().unwrap());
let mut iter = map.into_iter();
assert_eq!(iter.next(), Some((Some(header::CONTENT_LENGTH), "123".parse().unwrap())));
assert_eq!(iter.next(), Some((Some(header::CONTENT_TYPE), "json".parse().unwrap())));
assert!(iter.next().is_none());Multiple values per key.
let mut map = HeaderMap::new();
map.append(header::CONTENT_LENGTH, "123".parse().unwrap());
map.append(header::CONTENT_LENGTH, "456".parse().unwrap());
map.append(header::CONTENT_TYPE, "json".parse().unwrap());
map.append(header::CONTENT_TYPE, "html".parse().unwrap());
map.append(header::CONTENT_TYPE, "xml".parse().unwrap());
let mut iter = map.into_iter();
assert_eq!(iter.next(), Some((Some(header::CONTENT_LENGTH), "123".parse().unwrap())));
assert_eq!(iter.next(), Some((None, "456".parse().unwrap())));
assert_eq!(iter.next(), Some((Some(header::CONTENT_TYPE), "json".parse().unwrap())));
assert_eq!(iter.next(), Some((None, "html".parse().unwrap())));
assert_eq!(iter.next(), Some((None, "xml".parse().unwrap())));
assert!(iter.next().is_none());ยงtype Item = (Option<HeaderName>, T)
type Item = (Option<HeaderName>, T)
ยงimpl IntoResponse for HeaderMap
impl IntoResponse for HeaderMap
ยงfn into_response(self) -> Response<Body>
fn into_response(self) -> Response<Body>
ยงimpl IntoResponseParts for HeaderMap
impl IntoResponseParts for HeaderMap
ยงtype Error = Infallible
type Error = Infallible
ยงfn into_response_parts(
self,
res: ResponseParts,
) -> Result<ResponseParts, <HeaderMap as IntoResponseParts>::Error>
fn into_response_parts( self, res: ResponseParts, ) -> Result<ResponseParts, <HeaderMap as IntoResponseParts>::Error>
ยงimpl<'a, K, V, S, T> TryFrom<&'a HashMap<K, V, S>> for HeaderMap<T>
Try to convert a HashMap into a HeaderMap.
impl<'a, K, V, S, T> TryFrom<&'a HashMap<K, V, S>> for HeaderMap<T>
Try to convert a HashMap into a HeaderMap.
ยงExamples
use std::collections::HashMap;
use std::convert::TryInto;
use http::HeaderMap;
let mut map = HashMap::new();
map.insert("X-Custom-Header".to_string(), "my value".to_string());
let headers: HeaderMap = (&map).try_into().expect("valid headers");
assert_eq!(headers["X-Custom-Header"], "my value");impl<T> Eq for HeaderMap<T>where
T: Eq,
Auto Trait Implementationsยง
impl<T> Freeze for HeaderMap<T>
impl<T> RefUnwindSafe for HeaderMap<T>where
T: RefUnwindSafe,
impl<T> Send for HeaderMap<T>where
T: Send,
impl<T> Sync for HeaderMap<T>where
T: Sync,
impl<T> Unpin for HeaderMap<T>where
T: Unpin,
impl<T> UnwindSafe for HeaderMap<T>where
T: UnwindSafe,
Blanket Implementationsยง
Sourceยงimpl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
impl<S, D, Swp, Dwp, T> AdaptInto<D, Swp, Dwp, T> for Swhere
T: Real + Zero + Arithmetics + Clone,
Swp: WhitePoint<T>,
Dwp: WhitePoint<T>,
D: AdaptFrom<S, Swp, Dwp, T>,
Sourceยงfn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
fn adapt_into_using<M>(self, method: M) -> Dwhere
M: TransformMatrix<T>,
Sourceยงfn adapt_into(self) -> D
fn adapt_into(self) -> D
Sourceยงimpl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
impl<T, C> ArraysFrom<C> for Twhere
C: IntoArrays<T>,
Sourceยงfn arrays_from(colors: C) -> T
fn arrays_from(colors: C) -> T
Sourceยงimpl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
impl<T, C> ArraysInto<C> for Twhere
C: FromArrays<T>,
Sourceยงfn arrays_into(self) -> C
fn arrays_into(self) -> C
Sourceยงimpl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Sourceยงfn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Sourceยงimpl<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
impl<WpParam, T, U> Cam16IntoUnclamped<WpParam, T> for Uwhere
T: FromCam16Unclamped<WpParam, U>,
Sourceยงtype Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
type Scalar = <T as FromCam16Unclamped<WpParam, U>>::Scalar
parameters when converting.Sourceยงfn cam16_into_unclamped(
self,
parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>,
) -> T
fn cam16_into_unclamped( self, parameters: BakedParameters<WpParam, <U as Cam16IntoUnclamped<WpParam, T>>::Scalar>, ) -> T
self into C, using the provided parameters.Sourceยงimpl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Sourceยงimpl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
impl<T, C> ComponentsFrom<C> for Twhere
C: IntoComponents<T>,
Sourceยงfn components_from(colors: C) -> T
fn components_from(colors: C) -> T
ยงimpl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
ยงfn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>, which can then be
downcast into Box<dyn ConcreteType> where ConcreteType implements Trait.ยงfn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Rc<Trait> (where Trait: Downcast) to Rc<Any>, which can then be further
downcast into Rc<ConcreteType> where ConcreteType implements Trait.ยงfn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Anyโs vtable from &Traitโs.ยงfn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Anyโs vtable from &mut Traitโs.ยงimpl<T> DowncastSend for T
impl<T> DowncastSend for T
ยงimpl<T> DowncastSync for T
impl<T> DowncastSync for T
ยงimpl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
ยงfn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.ยงimpl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
ยงfn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
ยงimpl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
ยงfn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
Sourceยงimpl<T> FromAngle<T> for T
impl<T> FromAngle<T> for T
Sourceยงfn from_angle(angle: T) -> T
fn from_angle(angle: T) -> T
angle.ยงimpl<S, T> FromRequest<S, ViaParts> for T
impl<S, T> FromRequest<S, ViaParts> for T
ยงtype Rejection = <T as FromRequestParts<S>>::Rejection
type Rejection = <T as FromRequestParts<S>>::Rejection
ยงfn from_request(
req: Request<Body>,
state: &S,
) -> impl Future<Output = Result<T, <T as FromRequest<S, ViaParts>>::Rejection>>
fn from_request( req: Request<Body>, state: &S, ) -> impl Future<Output = Result<T, <T as FromRequest<S, ViaParts>>::Rejection>>
Sourceยงimpl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
impl<T, U> FromStimulus<U> for Twhere
U: IntoStimulus<T>,
Sourceยงfn from_stimulus(other: U) -> T
fn from_stimulus(other: U) -> T
other into Self, while performing the appropriate scaling,
rounding and clamping.ยงimpl<T, S> Handler<IntoResponseHandler, S> for T
impl<T, S> Handler<IntoResponseHandler, S> for T
ยงfn call(
self,
_req: Request<Body>,
_state: S,
) -> <T as Handler<IntoResponseHandler, S>>::Future
fn call( self, _req: Request<Body>, _state: S, ) -> <T as Handler<IntoResponseHandler, S>>::Future
ยงfn layer<L>(self, layer: L) -> Layered<L, Self, T, S>where
L: Layer<HandlerService<Self, T, S>> + Clone,
<L as Layer<HandlerService<Self, T, S>>>::Service: Service<Request<Body>>,
fn layer<L>(self, layer: L) -> Layered<L, Self, T, S>where
L: Layer<HandlerService<Self, T, S>> + Clone,
<L as Layer<HandlerService<Self, T, S>>>::Service: Service<Request<Body>>,
tower::Layer] to the handler. Read moreยงfn with_state(self, state: S) -> HandlerService<Self, T, S>
fn with_state(self, state: S) -> HandlerService<Self, T, S>
Service] by providing the stateยงimpl<H, T> HandlerWithoutStateExt<T> for H
impl<H, T> HandlerWithoutStateExt<T> for H
ยงfn into_service(self) -> HandlerService<H, T, ()>
fn into_service(self) -> HandlerService<H, T, ()>
Service] and no state.ยงfn into_make_service(self) -> IntoMakeService<HandlerService<H, T, ()>>
fn into_make_service(self) -> IntoMakeService<HandlerService<H, T, ()>>
MakeService and no state. Read moreยงfn into_make_service_with_connect_info<C>(
self,
) -> IntoMakeServiceWithConnectInfo<HandlerService<H, T, ()>, C>
fn into_make_service_with_connect_info<C>( self, ) -> IntoMakeServiceWithConnectInfo<HandlerService<H, T, ()>, C>
tokio only.MakeService which stores information
about the incoming connection and has no state. Read moreยงimpl<T> Instrument for T
impl<T> Instrument for T
ยงfn instrument(self, span: Span) -> Instrumented<Self> โ
fn instrument(self, span: Span) -> Instrumented<Self> โ
Sourceยงimpl<T, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
impl<T, U> IntoAngle<U> for Twhere
U: FromAngle<T>,
Sourceยงfn into_angle(self) -> U
fn into_angle(self) -> U
T.Sourceยงimpl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
impl<WpParam, T, U> IntoCam16Unclamped<WpParam, T> for Uwhere
T: Cam16FromUnclamped<WpParam, U>,
Sourceยงtype Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
type Scalar = <T as Cam16FromUnclamped<WpParam, U>>::Scalar
parameters when converting.Sourceยงfn into_cam16_unclamped(
self,
parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>,
) -> T
fn into_cam16_unclamped( self, parameters: BakedParameters<WpParam, <U as IntoCam16Unclamped<WpParam, T>>::Scalar>, ) -> T
self into C, using the provided parameters.Sourceยงimpl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
impl<T, U> IntoColor<U> for Twhere
U: FromColor<T>,
Sourceยงfn into_color(self) -> U
fn into_color(self) -> U
Sourceยงimpl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
impl<T, U> IntoColorUnclamped<U> for Twhere
U: FromColorUnclamped<T>,
Sourceยงfn into_color_unclamped(self) -> U
fn into_color_unclamped(self) -> U
Sourceยงimpl<T> IntoEither for T
impl<T> IntoEither for T
Sourceยงfn into_either(self, into_left: bool) -> Either<Self, Self> โ
fn into_either(self, into_left: bool) -> Either<Self, Self> โ
self into a Left variant of Either<Self, Self>
if into_left is true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreSourceยงfn into_either_with<F>(self, into_left: F) -> Either<Self, Self> โ
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> โ
self into a Left variant of Either<Self, Self>
if into_left(&self) returns true.
Converts self into a Right variant of Either<Self, Self>
otherwise. Read moreยงimpl<T, I> IntoReactiveValue<T, __IntoReactiveValueMarkerBaseCase> for Iwhere
I: Into<T>,
impl<T, I> IntoReactiveValue<T, __IntoReactiveValueMarkerBaseCase> for Iwhere
I: Into<T>,
ยงfn into_reactive_value(self) -> T
fn into_reactive_value(self) -> T
self into a T.Sourceยงimpl<T> IntoStimulus<T> for T
impl<T> IntoStimulus<T> for T
Sourceยงfn into_stimulus(self) -> T
fn into_stimulus(self) -> T
self into T, while performing the appropriate scaling,
rounding and clamping.ยงimpl<T> Pointable for T
impl<T> Pointable for T
ยงimpl<T> PolicyExt for Twhere
T: ?Sized,
impl<T> PolicyExt for Twhere
T: ?Sized,
ยงimpl<T> SerializableKey for T
impl<T> SerializableKey for T
ยงimpl<T> StorageAccess<T> for T
impl<T> StorageAccess<T> for T
ยงfn as_borrowed(&self) -> &T
fn as_borrowed(&self) -> &T
ยงfn into_taken(self) -> T
fn into_taken(self) -> T
Sourceยงimpl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
impl<T, C> TryComponentsInto<C> for Twhere
C: TryFromComponents<T>,
Sourceยงtype Error = <C as TryFromComponents<T>>::Error
type Error = <C as TryFromComponents<T>>::Error
try_into_colors fails to cast.Sourceยงfn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
fn try_components_into(self) -> Result<C, <T as TryComponentsInto<C>>::Error>
Sourceยงimpl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
impl<T, U> TryIntoColor<U> for Twhere
U: TryFromColor<T>,
Sourceยงfn try_into_color(self) -> Result<U, OutOfBounds<U>>
fn try_into_color(self) -> Result<U, OutOfBounds<U>>
OutOfBounds error is returned which contains
the unclamped color. Read more