Struct HeaderMap

Source
pub struct HeaderMap { /* private fields */ }
Expand description

A set of HTTP headers

HeaderMap is an multimap of HeaderName to values.

Implementations§

Source§

impl HeaderMap

Source

pub fn new() -> Self

Create an empty HeaderMap.

The map will be created without any capacity. This function will not allocate.

Source

pub fn with_capacity(capacity: usize) -> HeaderMap

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.

Source

pub fn len(&self) -> usize

Returns the number of keys stored in the map.

This number could be be less than or equal to actual headers stored in the map.

Source

pub fn is_empty(&self) -> bool

Returns true if the map contains no elements.

Source

pub fn clear(&mut self)

Clears the map, removing all key-value pairs. Keeps the allocated memory for reuse.

Source

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.

Source

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.

Source

pub fn get<N: AsName>(&self, name: N) -> Option<&HeaderValue>

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.

Source

pub fn get_all<N: AsName>(&self, name: N) -> GetAll<'_>

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.

Source

pub fn get_mut<N: AsName>(&mut self, name: N) -> Option<&mut HeaderValue>

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.

Source

pub fn contains_key<N: AsName>(&self, key: N) -> bool

Returns true if the map contains a value for the specified key.

Source

pub fn iter(&self) -> Iter<'_>

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.

Source

pub fn keys(&self) -> Keys<'_>

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.

Source

pub fn insert(&mut self, key: HeaderName, val: HeaderValue)

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.

Source

pub fn append(&mut self, key: HeaderName, value: HeaderValue)

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.

Source

pub fn remove<N: AsName>(&mut self, key: N)

Removes all headers for a particular header name from the map.

Trait Implementations§

Source§

impl Clone for HeaderMap

Source§

fn clone(&self) -> HeaderMap

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for HeaderMap

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for HeaderMap

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl<'de> Deserialize<'de> for HeaderMap

Source§

fn deserialize<D>(deserializer: D) -> Result<Self, D::Error>
where D: Deserializer<'de>,

Deserialize this value from the given Serde deserializer. Read more
Source§

impl From<HeaderMap> for HeaderMap

Convert http::HeaderMap to a HeaderMap

Source§

fn from(map: HeaderMap) -> HeaderMap

Converts to this type from the input type.
Source§

impl<N: Display, V> FromIterator<(N, V)> for HeaderMap
where HeaderName: TryFrom<N>, Value: TryFrom<V>, V: Debug,

Source§

fn from_iter<T: IntoIterator<Item = (N, V)>>(iter: T) -> Self

Creates a value from an iterator. Read more
Source§

impl<'a> IntoIterator for &'a HeaderMap

Source§

type Item = (&'a HeaderName, &'a HeaderValue)

The type of the elements being iterated over.
Source§

type IntoIter = Iter<'a>

Which kind of iterator are we turning this into?
Source§

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more
Source§

impl PartialEq for HeaderMap

Source§

fn eq(&self, other: &HeaderMap) -> bool

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

fn ne(&self, other: &Rhs) -> bool

Tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
Source§

impl Serialize for HeaderMap

Source§

fn serialize<S>(&self, serializer: S) -> Result<S::Ok, S::Error>
where S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl Eq for HeaderMap

Source§

impl StructuralPartialEq for HeaderMap

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<T> DeserializeOwned for T
where T: for<'de> Deserialize<'de>,