pub struct Headers(/* private fields */);Expand description
A collection of headers.
Implementations§
Source§impl Headers
impl Headers
Sourcepub fn get<H: FromHeaders>(&self) -> Result<H>
pub fn get<H: FromHeaders>(&self) -> Result<H>
Gets the headers represented by H, or return an error if the header is not found.
Sourcepub fn get_optional<H: FromHeaders>(&self) -> Result<Option<H>, H::Error>
pub fn get_optional<H: FromHeaders>(&self) -> Result<Option<H>, H::Error>
Gets the headers represented by H, if they are present.
This method returns one of the following three values:
Ok(Some(...))if the relevant headers are present and could be parsed into the value.Ok(None)if the relevant headers are not present, so no attempt to parse them can be made.Err(...)if an error occurred when trying to parse the headers. This likely indicates that the headers are present but invalid.
Sourcepub fn get_optional_string(&self, key: &HeaderName) -> Option<String>
pub fn get_optional_string(&self, key: &HeaderName) -> Option<String>
Optionally get a header value as a String.
Sourcepub fn get_str(&self, key: &HeaderName) -> Result<&str>
pub fn get_str(&self, key: &HeaderName) -> Result<&str>
Get a header value as a str, or err if it is not found.
Sourcepub fn get_optional_str(&self, key: &HeaderName) -> Option<&str>
pub fn get_optional_str(&self, key: &HeaderName) -> Option<&str>
Optionally get a header value as a str.
Sourcepub fn get_as<V, E>(&self, key: &HeaderName) -> Result<V>
pub fn get_as<V, E>(&self, key: &HeaderName) -> Result<V>
Get a header value parsing it as the type, or err if it’s not found or it fails to parse.
Sourcepub fn get_optional_as<V, E>(&self, key: &HeaderName) -> Result<Option<V>>
pub fn get_optional_as<V, E>(&self, key: &HeaderName) -> Result<Option<V>>
Optionally get a header value parsing it as the type, or err if it fails to parse.
Sourcepub fn get_with<'a, V, F, E>(&'a self, key: &HeaderName, parser: F) -> Result<V>
pub fn get_with<'a, V, F, E>(&'a self, key: &HeaderName, parser: F) -> Result<V>
Get a header value using the parser, or err if it is not found or fails to parse.
Sourcepub fn get_optional_with<'a, V, F, E>(
&'a self,
key: &HeaderName,
parser: F,
) -> Result<Option<V>>
pub fn get_optional_with<'a, V, F, E>( &'a self, key: &HeaderName, parser: F, ) -> Result<Option<V>>
Optionally get a header value using the parser, or err if it fails to parse.
Sourcepub fn add<H>(&mut self, header: H) -> Result<(), H::Error>where
H: AsHeaders,
pub fn add<H>(&mut self, header: H) -> Result<(), H::Error>where
H: AsHeaders,
Add headers to the headers collection.
§Errors
The error this returns depends on the type H.
Many header types are infallible, return a Result with Infallible as the error type.
In this case, you can safely .unwrap() the value without risking a panic.
Sourcepub fn iter(&self) -> impl Iterator<Item = (&HeaderName, &HeaderValue)>
pub fn iter(&self) -> impl Iterator<Item = (&HeaderName, &HeaderValue)>
Iterate over all the header name/value pairs.
Sourcepub fn remove<K>(&mut self, key: K) -> Option<HeaderValue>where
K: Into<HeaderName>,
pub fn remove<K>(&mut self, key: K) -> Option<HeaderValue>where
K: Into<HeaderName>,
Remove a header by name, returning the previous value if present.
Trait Implementations§
impl Eq for Headers
Source§impl From<HashMap<HeaderName, HeaderValue>> for Headers
impl From<HashMap<HeaderName, HeaderValue>> for Headers
Source§fn from(c: HashMap<HeaderName, HeaderValue>) -> Self
fn from(c: HashMap<HeaderName, HeaderValue>) -> Self
Source§impl IntoIterator for Headers
impl IntoIterator for Headers
Source§type Item = (HeaderName, HeaderValue)
type Item = (HeaderName, HeaderValue)
Source§type IntoIter = IntoIter<HeaderName, HeaderValue>
type IntoIter = IntoIter<HeaderName, HeaderValue>
impl StructuralPartialEq for Headers
Auto Trait Implementations§
impl Freeze for Headers
impl RefUnwindSafe for Headers
impl Send for Headers
impl Sync for Headers
impl Unpin for Headers
impl UnsafeUnpin for Headers
impl UnwindSafe for Headers
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.