Skip to main content

HeaderMapExt

Trait HeaderMapExt 

pub trait HeaderMapExt: Sealed {
    // Required methods
    fn typed_insert<H>(&mut self, header: H)
       where H: HeaderEncode;
    fn typed_get<H>(&self) -> Option<H>
       where H: HeaderDecode;
    fn typed_try_get<H>(&self) -> Result<Option<H>, Error>
       where H: HeaderDecode;
    fn remove_all<K>(&mut self, name: K) -> usize
       where K: AsHeaderName + Clone;
    fn remove_all_values<K>(&mut self, name: K) -> Vec<HeaderValue>
       where K: AsHeaderName + Clone;
}
Available on crate feature http only.
Expand description

An extension trait adding “typed” methods to http::HeaderMap.

Required Methods§

fn typed_insert<H>(&mut self, header: H)
where H: HeaderEncode,

Inserts the typed header into this HeaderMap.

fn typed_get<H>(&self) -> Option<H>
where H: HeaderDecode,

Tries to find the header by name, and then decode it into H.

fn typed_try_get<H>(&self) -> Result<Option<H>, Error>
where H: HeaderDecode,

Tries to find the header by name, and then decode it into H.

fn remove_all<K>(&mut self, name: K) -> usize
where K: AsHeaderName + Clone,

Remove every value associated with a header name and return how many were removed.

Note: HeaderMap::remove already removes the whole entry (all values) for a header — it just returns only the first value as Option<HeaderValue>. This method gives callers an accurate count without needing to call HeaderMap::get_all manually beforehand. Use remove_all_values when the values themselves are needed.

fn remove_all_values<K>(&mut self, name: K) -> Vec<HeaderValue>
where K: AsHeaderName + Clone,

Remove every value associated with a header name and return them in iteration order.

Useful when you need to inspect, log, or relocate the removed values — HeaderMap::remove only surfaces the first.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§