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

Trillium’s header map type

Implementations§

§

impl Headers

pub fn with_capacity(capacity: usize) -> Headers

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

pub fn new() -> Headers

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

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

Extend the capacity of the known headers map by this many

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

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

pub fn is_empty(&self) -> bool

Are there zero headers?

pub fn len(&self) -> usize

How many unique HeaderName have been added to these Headers? Note that each header name may have more than one HeaderValue.

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

pub fn append_all(&mut self, other: Headers)

A slightly more efficient way to combine two Headers than using Extend

pub fn insert_all(&mut self, other: Headers)

Combine two Headers, replacing any existing header values

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

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.

pub fn get_str<'a>(&self, name: impl Into<HeaderName<'a>>) -> Option<&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.

pub fn get<'a>(&self, name: impl Into<HeaderName<'a>>) -> Option<&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

pub fn remove<'a>( &mut self, name: impl Into<HeaderName<'a>> ) -> 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.

pub fn get_values<'a>( &self, name: impl Into<HeaderName<'a>> ) -> Option<&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.

pub fn has_header<'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.

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

pub fn contains_ignore_ascii_case<'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 .

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

Chainable method to insert a header

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

Chainable method to append a header

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

Chainable method to remove a header

pub fn without_headers<I, H>(self, names: I) -> Headers
where I: IntoIterator<Item = H>, H: Into<HeaderName<'static>>,

Chainable method to remove multiple headers by name

pub fn remove_all<I, H>(&mut self, names: I)
where I: IntoIterator<Item = H>, H: Into<HeaderName<'static>>,

remove multiple headers by name

pub fn try_insert_with<F, V>( &mut self, name: impl Into<HeaderName<'static>>, values_fn: F )
where F: Fn() -> V, V: Into<HeaderValues>,

if a key does not exist already, execute the provided function and insert a value

this can be useful to avoid calculating an unnecessary header value, or checking for the presence of a key before insertion

Trait Implementations§

§

impl Clone for Headers

§

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
§

impl Debug for Headers

§

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

Formats the value using the given formatter. Read more
§

impl Default for Headers

§

fn default() -> Headers

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

impl Display for Headers

§

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

Formats the value using the given formatter. Read more
§

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

§

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
§

impl<HN, HV> FromIterator<(HN, HV)> for Headers
where HN: Into<HeaderName<'static>>, HV: Into<HeaderValues>,

§

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

Creates a value from an iterator. Read more
§

impl Handler for Headers

§

fn run<'life0, 'async_trait>( &'life0 self, conn: Conn ) -> Pin<Box<dyn Future<Output = Conn> + Send + 'async_trait>>
where 'life0: 'async_trait, Headers: 'async_trait,

Executes this handler, performing any modifications to the Conn that are desired.
§

fn init<'life0, 'life1, 'async_trait>( &'life0 mut self, _info: &'life1 mut Info ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait, 'life1: 'async_trait, Self: 'async_trait,

Performs one-time async set up on a mutable borrow of the Handler before the server starts accepting requests. This allows a Handler to be defined in synchronous code but perform async setup such as establishing a database connection or fetching some state from an external source. This is optional, and chances are high that you do not need this. Read more
§

fn before_send<'life0, 'async_trait>( &'life0 self, conn: Conn ) -> Pin<Box<dyn Future<Output = Conn> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: 'async_trait,

Performs any final modifications to this conn after all handlers have been run. Although this is a slight deviation from the simple conn->conn->conn chain represented by most Handlers, it provides an easy way for libraries to effectively inject a second handler into a response chain. This is useful for loggers that need to record information both before and after other handlers have run, as well as database transaction handlers and similar library code. Read more
§

fn has_upgrade(&self, _upgrade: &Upgrade<BoxedTransport>) -> bool

predicate function answering the question of whether this Handler would like to take ownership of the negotiated Upgrade. If this returns true, you must implement [Handler::upgrade]. The first handler that responds true to this will receive ownership of the [trillium::Upgrade][crate::Upgrade] in a subsequent call to [Handler::upgrade]
§

fn upgrade<'life0, 'async_trait>( &'life0 self, _upgrade: Upgrade<BoxedTransport> ) -> Pin<Box<dyn Future<Output = ()> + Send + 'async_trait>>
where 'life0: 'async_trait, Self: 'async_trait,

This will only be called if the handler reponds true to [Handler::has_upgrade] and will only be called once for this upgrade. There is no return value, and this function takes exclusive ownership of the underlying transport once this is called. You can downcast the transport to whatever the source transport type is and perform any non-http protocol communication that has been negotiated. You probably don’t want this unless you’re implementing something like websockets. Please note that for many transports such as TcpStreams, dropping the transport (and therefore the Upgrade) will hang up / disconnect.
§

fn name(&self) -> Cow<'static, str>

Customize the name of your handler. This is used in Debug implementations. The default is the type name of this handler.
§

impl<'a> IntoIterator for &'a Headers

§

type Item = (HeaderName<'a>, &'a HeaderValues)

The type of the elements being iterated over.
§

type IntoIter = Iter<'a>

Which kind of iterator are we turning this into?
§

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

Creates an iterator from a value. Read more
§

impl IntoIterator for Headers

§

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

The type of the elements being iterated over.
§

type IntoIter = IntoIter

Which kind of iterator are we turning this into?
§

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

Creates an iterator from a value. Read more
§

impl PartialEq for Headers

§

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.
§

impl Eq for Headers

§

impl StructuralEq for Headers

§

impl StructuralPartialEq for Headers

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
§

impl<Q, K> Equivalent<K> for Q
where 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

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,

§

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> ToString for T
where T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

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

§

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>,

§

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.