Skip to main content

HeaderMap

Struct HeaderMap 

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

A compact header map using SmallVec for inline storage.

§Example

use armature_core::headers::HeaderMap;

let mut headers = HeaderMap::new();
headers.insert("Content-Type", "application/json");
headers.insert("Accept", "text/html");

// Lookup is case-insensitive; the value comes back as a `&str`.
assert_eq!(headers.get("content-type"), Some("application/json"));
assert!(headers.is_inline()); // Still on stack

Implementations§

Source§

impl HeaderMap

Source

pub const fn new() -> Self

Create a new empty header map.

Source

pub fn with_capacity(capacity: usize) -> Self

Create with pre-allocated capacity.

If capacity <= INLINE_HEADERS, no heap allocation occurs.

Source

pub fn is_inline(&self) -> bool

Check if storage is inline (no heap allocation).

Source

pub fn len(&self) -> usize

Get the number of headers.

Source

pub fn is_empty(&self) -> bool

Check if empty.

Source

pub fn get(&self, name: &str) -> Option<&str>

The value of name as UTF-8, case-insensitively.

Returns None for a value that is not valid UTF-8; use HeaderMap::get_bytes for those.

Source

pub fn get_bytes(&self, name: &str) -> Option<&Bytes>

The raw value of name, case-insensitively.

Source

pub fn get_id(&self, id: &HeaderId) -> Option<&Bytes>

The raw value for an already-interned name.

The hot-path accessor: no interning, and for a well-known name the comparison is on the enum discriminant.

Source

pub fn get_ignore_case(&self, name: &str) -> Option<&str>

The value of name as UTF-8, case-insensitively.

Identical to HeaderMap::get; kept because call sites use both names.

Source

pub fn contains(&self, name: &str) -> bool

Check if header exists (case-insensitive).

Source

pub fn contains_key(&self, name: &str) -> bool

Check if header exists (case-insensitive).

HashMap-compatible alias for contains.

Source

pub fn insert( &mut self, name: impl AsRef<str>, value: impl HeaderValueInput, ) -> Option<Bytes>

Insert a header, replacing any existing header with the same name.

Returns the old value if one was replaced.

Source

pub fn append(&mut self, name: impl AsRef<str>, value: impl HeaderValueInput)

Append a header, allowing duplicates.

Unlike insert, this does not replace. Use it for fields that may repeat, such as Set-Cookie.

Source

pub fn remove(&mut self, name: &str) -> Option<Bytes>

Remove a header by name (case-insensitive), returning its value.

Source

pub fn remove_all(&mut self, name: &str) -> usize

Remove every header with the given name, returning how many were removed.

Source

pub fn iter(&self) -> impl Iterator<Item = (&str, &str)>

Iterate over headers as (name, value), skipping non-UTF-8 values.

Source

pub fn iter_raw(&self) -> impl Iterator<Item = (&HeaderId, &Bytes)>

Iterate over every header, including those with non-UTF-8 values.

Source

pub fn names(&self) -> impl Iterator<Item = &str>

Iterate over header names, lowercased.

Source

pub fn keys(&self) -> impl Iterator<Item = &str>

Iterate over header names.

HashMap-compatible alias for names.

Source

pub fn values(&self) -> impl Iterator<Item = &str>

Iterate over header values, skipping non-UTF-8 ones.

Source

pub fn get_all(&self, name: &str) -> Vec<&str>

Every value for a header name, for multi-value fields.

Source

pub fn clear(&mut self)

Clear all headers.

Source

pub fn extend<I, K, V>(&mut self, iter: I)
where I: IntoIterator<Item = (K, V)>, K: AsRef<str>, V: HeaderValueInput,

Extend with headers from an iterator.

Source

pub fn to_hash_map(&self) -> HashMap<String, String>

Convert to a HashMap, for compatibility.

Names come out lowercased and non-UTF-8 values are dropped. This allocates a String per name and value — reach for it only when a HashMap is genuinely required.

Source

pub fn from_hash_map(map: HashMap<String, String>) -> Self

Create from a HashMap.

Source

pub fn content_type(&self) -> Option<&str>

Get the Content-Type header.

Source

pub fn content_length(&self) -> Option<usize>

Get the Content-Length header as a usize.

Source

pub fn accept(&self) -> Option<&str>

Get the Accept header.

Source

pub fn authorization(&self) -> Option<&str>

Get the Authorization header.

Source

pub fn user_agent(&self) -> Option<&str>

Get the User-Agent header.

Source

pub fn host(&self) -> Option<&str>

Get the Host header.

Source

pub fn cookie(&self) -> Option<&str>

Get the Cookie header.

Source

pub fn is_keep_alive(&self) -> bool

Check for a keep-alive connection.

Source

pub fn is_chunked(&self) -> bool

Check for chunked transfer encoding.

Source

pub fn set_content_type(&mut self, value: impl HeaderValueInput)

Set the Content-Type header.

Source

pub fn set_content_length(&mut self, len: usize)

Set the Content-Length header.

Trait Implementations§

Source§

impl Clone for HeaderMap

Source§

fn clone(&self) -> HeaderMap

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · 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() -> HeaderMap

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

impl Extend<(String, String)> for HeaderMap

Source§

fn extend<I: IntoIterator<Item = (String, String)>>(&mut self, iter: I)

Extends a collection with the contents of an iterator. Read more
Source§

fn extend_one(&mut self, item: A)

🔬This is a nightly-only experimental API. (extend_one)
Extends a collection with exactly one element.
Source§

fn extend_reserve(&mut self, additional: usize)

🔬This is a nightly-only experimental API. (extend_one)
Reserves capacity in a collection for the given number of additional elements. Read more
Source§

impl From<HashMap<String, String>> for HeaderMap

Source§

fn from(map: HashMap<String, String>) -> Self

Converts to this type from the input type.
Source§

impl From<HeaderMap> for HashMap<String, String>

Source§

fn from(map: HeaderMap) -> Self

Converts to this type from the input type.
Source§

impl<K, V> FromIterator<(K, V)> for HeaderMap
where K: AsRef<str>, V: HeaderValueInput,

Source§

fn from_iter<I: IntoIterator<Item = (K, V)>>(iter: I) -> Self

Creates a value from an iterator. Read more
Source§

impl Index<&str> for HeaderMap

Source§

type Output = str

The returned type after indexing.
Source§

fn index(&self, name: &str) -> &Self::Output

Performs the indexing (container[index]) operation. Read more
Source§

impl<'a> IntoIterator for &'a HeaderMap

Source§

type Item = (&'a str, &'a str)

The type of the elements being iterated over.
Source§

type IntoIter = FilterMap<Iter<'a, Header>, fn(&'a Header) -> Option<(&'a str, &'a str)>>

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 IntoIterator for HeaderMap

Source§

type Item = (String, String)

The type of the elements being iterated over.
Source§

type IntoIter = FilterMap<IntoIter<[Header; 12]>, fn(Header) -> Option<(String, String)>>

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

fn into_iter(self) -> Self::IntoIter

Creates an iterator from a value. Read more

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<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
where ST: ?Sized, DT: ?Sized,

Source§

impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
where ST: ?Sized, DT: ?Sized,

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<R, D> DepsPresent<D> for R

Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Injectable for T
where T: Send + Sync + 'static,

Source§

fn type_id_of() -> TypeId
where Self: Sized,

Returns the TypeId of this type (for internal use)
Source§

fn type_name_of() -> &'static str
where Self: Sized,

Returns the type name for debugging
Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> Provider for T
where T: Injectable,

Source§

impl<T> Read<Exclusive, BecauseExclusive> for T
where T: ?Sized,

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V

Source§

impl<R, D> VerifyDeps<D> for R

Source§

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more