HeaderMap

Struct HeaderMap 

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

A compact header map using SmallVec for inline storage.

Stores up to 12 headers inline (on the stack), only allocating on the heap if more headers are added.

§Example

use armature_core::headers::HeaderMap;

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

assert_eq!(headers.get("content-type"), Some(&"application/json".to_string()));
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<&String>

Get header value by name (case-insensitive).

Source

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

Get header value by name, with lowercase fallback.

First tries exact match, then lowercase. This handles the common case where headers might be stored in different cases.

Source

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

Check if header exists (case-insensitive).

Source

pub fn insert( &mut self, name: impl Into<String>, value: impl Into<String>, ) -> Option<String>

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

Returns the old value if replaced.

Source

pub fn append(&mut self, name: impl Into<String>, value: impl Into<String>)

Append a header (allows duplicates).

Unlike insert, this doesn’t replace existing headers. Use for headers that can have multiple values (e.g., Set-Cookie).

Source

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

Remove a header by name (case-insensitive).

Returns the removed value if found.

Source

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

Remove all headers with given name (case-insensitive).

Returns number of headers removed.

Source

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

Iterate over all headers.

Source

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

Iterate over header names.

Source

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

Iterate over header values.

Source

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

Get all values for a header name (for multi-value headers).

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: Into<String>, V: Into<String>,

Extend with headers from iterator.

Source

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

Convert to HashMap (for compatibility).

Source

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

Create from HashMap.

Source

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

Get Content-Type header.

Source

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

Get Content-Length header as usize.

Source

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

Get Accept header.

Source

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

Get Authorization header.

Source

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

Get User-Agent header.

Source

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

Get Host header.

Source

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

Get Cookie header.

Source

pub fn is_keep_alive(&self) -> bool

Check if Keep-Alive connection.

Source

pub fn is_chunked(&self) -> bool

Check if chunked transfer encoding.

Source

pub fn set_content_type(&mut self, value: impl Into<String>)

Set Content-Type header.

Source

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

Set Content-Length header.

Trait Implementations§

Source§

impl ArmatureHeaderMapExt for HeaderMap

Source§

fn to_http_headers(&self) -> HeaderMap

Convert to http::HeaderMap.
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() -> HeaderMap

Returns the “default value” for a type. 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: Into<String>, V: Into<String>,

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 = String

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 String, &'a String)

The type of the elements being iterated over.
Source§

type IntoIter = Map<Iter<'a, Header>, fn(&'a Header) -> (&'a String, &'a 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
Source§

impl IntoIterator for HeaderMap

Source§

type Item = (String, String)

The type of the elements being iterated over.
Source§

type IntoIter = Map<IntoIter<[Header; 12]>, fn(Header) -> (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<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> 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> 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<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
Source§

impl<T> Provider for T
where T: Injectable,