Struct trillium_http::Headers
source · [−]pub struct Headers { /* private fields */ }
Expand description
Trillium’s header map type
Implementations
sourceimpl Headers
impl Headers
sourcepub fn with_capacity(capacity: usize) -> Self
pub fn with_capacity(capacity: usize) -> Self
Construct a new Headers, expecting to see at least this many known headers.
sourcepub fn reserve(&mut self, additional: usize)
pub fn reserve(&mut self, additional: usize)
Extend the capacity of the known headers map by this many
sourcepub fn iter(&self) -> impl Iterator<Item = (HeaderName<'_>, &HeaderValues)>
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.
sourcepub fn append(
&mut self,
name: impl Into<HeaderName<'static>>,
value: impl Into<HeaderValues>
)
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
sourcepub fn insert(
&mut self,
name: impl Into<HeaderName<'static>>,
value: impl Into<HeaderValues>
)
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
sourcepub fn try_insert(
&mut self,
name: impl Into<HeaderName<'static>>,
value: impl Into<HeaderValues>
)
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.
sourcepub fn get_str<'a>(&'a self, name: impl Into<HeaderName<'a>>) -> Option<&str>
pub fn get_str<'a>(&'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.
sourcepub fn get<'a>(
&'a self,
name: impl Into<HeaderName<'a>>
) -> Option<&HeaderValue>
pub fn get<'a>(
&'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
sourcepub fn remove(
&mut self,
name: impl Into<HeaderName<'static>>
) -> Option<HeaderValues>
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.
sourcepub fn get_values<'a>(
&'a self,
name: impl Into<HeaderName<'a>>
) -> Option<&HeaderValues>
pub fn get_values<'a>(
&'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
.
sourcepub fn has_header<'a>(&'a self, name: impl Into<HeaderName<'a>>) -> bool
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.
sourcepub fn eq_ignore_ascii_case<'a>(
&'a self,
name: impl Into<HeaderName<'a>>,
needle: &str
) -> bool
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
sourcepub fn contains_ignore_ascii_case<'a>(
&'a self,
name: impl Into<HeaderName<'a>>,
needle: &str
) -> bool
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 .
Trait Implementations
sourceimpl<HN, HV> Extend<(HN, HV)> for Headers where
HN: Into<HeaderName<'static>>,
HV: Into<HeaderValues>,
impl<HN, HV> Extend<(HN, HV)> for Headers where
HN: Into<HeaderName<'static>>,
HV: Into<HeaderValues>,
sourcefn extend<T: IntoIterator<Item = (HN, HV)>>(&mut self, iter: T)
fn extend<T: IntoIterator<Item = (HN, HV)>>(&mut self, iter: T)
Extends a collection with the contents of an iterator. Read more
sourcefn extend_one(&mut self, item: A)
fn extend_one(&mut self, item: A)
extend_one
)Extends a collection with exactly one element.
sourcefn extend_reserve(&mut self, additional: usize)
fn extend_reserve(&mut self, additional: usize)
extend_one
)Reserves capacity in a collection for the given number of additional elements. Read more
sourceimpl<HN, HV> FromIterator<(HN, HV)> for Headers where
HN: Into<HeaderName<'static>>,
HV: Into<HeaderValues>,
impl<HN, HV> FromIterator<(HN, HV)> for Headers where
HN: Into<HeaderName<'static>>,
HV: Into<HeaderValues>,
sourceimpl IntoIterator for Headers
impl IntoIterator for Headers
Auto Trait Implementations
impl RefUnwindSafe for Headers
impl Send for Headers
impl Sync for Headers
impl Unpin for Headers
impl UnwindSafe for Headers
Blanket Implementations
sourceimpl<T> BorrowMut<T> for T where
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
const: unstable · sourcefn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more
sourceimpl<T> ToOwned for T where
T: Clone,
impl<T> ToOwned for T where
T: Clone,
type Owned = T
type Owned = T
The resulting type after obtaining ownership.
sourcefn clone_into(&self, target: &mut T)
fn clone_into(&self, target: &mut T)
toowned_clone_into
)Uses borrowed data to replace owned data, usually by cloning. Read more