pub struct HeaderMap { /* private fields */ }Expand description
Implementations§
Source§impl HeaderMap
impl HeaderMap
Sourcepub fn new() -> HeaderMap
pub fn new() -> HeaderMap
Creates an empty HeaderMap.
The map will be created without any capacity. This function will not allocate.
Sourcepub fn with_capacity(capacity: usize) -> HeaderMap
pub fn with_capacity(capacity: usize) -> HeaderMap
Creates 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.
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the number of keys stored in the map.
This counts distinct header names, not the total number of values.
Sourcepub fn clear(&mut self)
pub fn clear(&mut self)
Clears the map, removing all key-value pairs. Keeps the allocated memory for reuse.
Sourcepub 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.
Sourcepub 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.
Sourcepub fn get<N>(&self, name: N) -> Option<&HeaderValue>where
N: AsName,
pub fn get<N>(&self, name: N) -> Option<&HeaderValue>where
N: AsName,
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.
Sourcepub fn get_all<N>(&self, name: N) -> GetAll<'_> ⓘwhere
N: AsName,
pub fn get_all<N>(&self, name: N) -> GetAll<'_> ⓘwhere
N: AsName,
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. The iterator is empty if there are no values associated with the key.
Sourcepub fn get_mut<N>(&mut self, name: N) -> Option<&mut HeaderValue>where
N: AsName,
pub fn get_mut<N>(&mut self, name: N) -> Option<&mut HeaderValue>where
N: AsName,
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 get_all to get all values associated with a given
key. Returns None if there are no values associated with the key.
Sourcepub fn contains_key<N>(&self, key: N) -> boolwhere
N: AsName,
pub fn contains_key<N>(&self, key: N) -> boolwhere
N: AsName,
Returns true if the map contains a value for the specified key.
Sourcepub fn iter(&self) -> Iter<'_> ⓘ
pub fn iter(&self) -> Iter<'_> ⓘ
An iterator visiting all key-value pairs.
The iteration order is arbitrary and may vary between maps. Each key is yielded once per associated value.
Sourcepub fn keys(&self) -> Keys<'_>
pub fn keys(&self) -> Keys<'_>
An iterator visiting all keys.
The iteration order is arbitrary and may vary between maps. Each key is yielded only once, even if it has multiple associated values.
Sourcepub fn insert(&mut self, key: HeaderName, val: HeaderValue)
pub fn insert(&mut self, key: HeaderName, val: HeaderValue)
Inserts a key-value pair into the map.
The new value replaces all values previously associated with the key.
The key is not updated, though; this matters for types that can be ==
without being identical.
Sourcepub fn append(&mut self, key: HeaderName, value: HeaderValue)
pub fn append(&mut self, key: HeaderName, value: HeaderValue)
Inserts a key-value pair into the map.
The value is appended after any values already associated with the key. The stored key itself is not replaced when an equivalent key exists.
Trait Implementations§
Source§impl<'de> Deserialize<'de> for HeaderMap
impl<'de> Deserialize<'de> for HeaderMap
Source§fn deserialize<D>(
deserializer: D,
) -> Result<HeaderMap, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
fn deserialize<D>(
deserializer: D,
) -> Result<HeaderMap, <D as Deserializer<'de>>::Error>where
D: Deserializer<'de>,
impl Eq for HeaderMap
Source§impl<'a> IntoIterator for &'a HeaderMap
impl<'a> IntoIterator for &'a HeaderMap
Source§impl Serialize for HeaderMap
impl Serialize for HeaderMap
Source§fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
fn serialize<S>(
&self,
serializer: S,
) -> Result<<S as Serializer>::Ok, <S as Serializer>::Error>where
S: Serializer,
impl StructuralPartialEq for HeaderMap
Auto Trait Implementations§
impl Freeze for HeaderMap
impl RefUnwindSafe for HeaderMap
impl Send for HeaderMap
impl Sync for HeaderMap
impl Unpin for HeaderMap
impl UnsafeUnpin for HeaderMap
impl UnwindSafe for HeaderMap
Blanket Implementations§
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<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> DeserializeOwned for Twhere
T: for<'de> Deserialize<'de>,
§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.