Struct trillium::Headers

source ·
pub struct Headers { /* private fields */ }
Expand description

Trillium’s header map type

Implementations§

source§

impl Headers

source

pub fn with_capacity(capacity: usize) -> Headers

Construct a new Headers, expecting to see at least this many known headers.

source

pub fn new() -> Headers

Construct a new headers with a default capacity of 15 known headers

source

pub fn reserve(&mut self, additional: usize)

Extend the capacity of the known headers map by this many

source

pub fn iter(&self) -> impl Iterator<Item = (HeaderName<'_>, &HeaderValues)>

Return an iterator over borrowed header names and header values. First yields the known headers and then the unknown headers, if any.

source

pub fn append( &mut self, name: impl Into<HeaderName<'static>>, value: impl Into<HeaderValues> )

add the header value or header values into this header map. If there is already a header with the same name, the new values will be added to the existing ones. To replace any existing values, use Headers::insert

source

pub fn insert( &mut self, name: impl Into<HeaderName<'static>>, value: impl Into<HeaderValues> )

Add a header value or header values into this header map. If a header already exists with the same name, it will be replaced. To combine, see Headers::append

source

pub fn try_insert( &mut self, name: impl Into<HeaderName<'static>>, value: impl Into<HeaderValues> )

Add a header value or header values into this header map if and only if there is not already a header with the same name.

source

pub fn get_str<'a>(&'a self, name: impl Into<HeaderName<'a>>) -> Option<&'a str>

Retrieves a &str header value if there is at least one header in the map with this name. If there are several headers with the same name, this follows the behavior defined at HeaderValues::one. Returns None if there is no header with the provided header name.

source

pub fn get<'a>( &'a self, name: impl Into<HeaderName<'a>> ) -> Option<&'a HeaderValue>

Retrieves a singular header value from this header map. If there are several headers with the same name, this follows the behavior defined at HeaderValues::one. Returns None if there is no header with the provided header name

source

pub fn remove( &mut self, name: impl Into<HeaderName<'static>> ) -> Option<HeaderValues>

Takes all headers with the provided header name out of this header map and returns them. Returns None if the header did not have an entry in this map.

source

pub fn get_values<'a>( &'a self, name: impl Into<HeaderName<'a>> ) -> Option<&'a HeaderValues>

Retrieves a reference to all header values with the provided header name. If you expect there to be only one value, use Headers::get.

source

pub fn has_header<'a>(&'a self, name: impl Into<HeaderName<'a>>) -> bool

Predicate function to check whether this header map contains the provided header name. If you are using this to conditionally insert a value, consider using Headers::try_insert instead.

source

pub fn eq_ignore_ascii_case<'a>( &'a self, name: impl Into<HeaderName<'a>>, needle: &str ) -> bool

Convenience function to check whether the value contained in this header map for the provided name is ascii-case-insensitively equal to the provided comparison &str. Returns false if there is no value for the name

source

pub fn contains_ignore_ascii_case<'a>( &'a self, name: impl Into<HeaderName<'a>>, needle: &str ) -> bool

Convenience function to check whether the value contained in this header map for the provided name. Prefer testing against a lower case string, as the implementation currently has to allocate if .

source

pub fn with_inserted_header( self, name: impl Into<HeaderName<'static>>, values: impl Into<HeaderValues> ) -> Headers

Chainable method to insert a header

source

pub fn with_appended_header( self, name: impl Into<HeaderName<'static>>, values: impl Into<HeaderValues> ) -> Headers

Chainable method to append a header

source

pub fn without_header(self, name: impl Into<HeaderName<'static>>) -> Headers

Chainable method to remove a header

Trait Implementations§

source§

impl Clone for Headers

source§

fn clone(&self) -> Headers

Returns a copy 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 Headers

source§

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

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

impl Default for Headers

source§

fn default() -> Headers

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

impl<HN, HV> Extend<(HN, HV)> for Headerswhere HN: Into<HeaderName<'static>>, HV: Into<HeaderValues>,

source§

fn extend<T>(&mut self, iter: T)where T: IntoIterator<Item = (HN, HV)>,

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<HN, HV> FromIterator<(HN, HV)> for Headerswhere HN: Into<HeaderName<'static>>, HV: Into<HeaderValues>,

source§

fn from_iter<T>(iter: T) -> Headerswhere T: IntoIterator<Item = (HN, HV)>,

Creates a value from an iterator. Read more
source§

impl IntoIterator for Headers

§

type Item = (HeaderName<'static>, HeaderValues)

The type of the elements being iterated over.
§

type IntoIter = Box<dyn Iterator<Item = <Headers as IntoIterator>::Item> + 'static, Global>

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

fn into_iter(self) -> <Headers as IntoIterator>::IntoIter

Creates an iterator from a value. Read more
source§

impl PartialEq<Headers> for Headers

source§

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

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

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

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl Eq for Headers

source§

impl StructuralEq for Headers

source§

impl StructuralPartialEq for Headers

Auto Trait Implementations§

Blanket Implementations§

source§

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

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

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

const: unstable · source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

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

const: unstable · source§

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

Mutably borrows from an owned value. Read more
§

impl<Q, K> Equivalent<K> for Qwhere Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
source§

impl<T> From<T> for T

const: unstable · source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

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

const: unstable · 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 Twhere T: Clone,

§

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 Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.
source§

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

§

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

The type returned in the event of a conversion error.
const: unstable · source§

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

Performs the conversion.