Trait TypedHeaders

Source
pub trait TypedHeaders {
    // Required methods
    fn decode<H>(&self) -> Result<H>
       where H: StandardHeader;
    fn try_decode<H>(&self) -> Option<Result<H>>
       where H: StandardHeader;
    fn encode<H>(&mut self, value: &H)
       where H: StandardHeader + Display;
    fn encode_append<H>(&mut self, value: &H)
       where H: StandardHeader + Display;
}
Expand description

Extension trait for decode (parsing) and encode (serialization) of typed headers from/to a collection of headers such as http::HeaderMap.

Required Methods§

Source

fn decode<H>(&self) -> Result<H>
where H: StandardHeader,

Decode and return Header type H or Error::Header.

Error::Header is returned on failed parse, or for a single-valued Header type, if no values or multiple values are found in the collection. Multi-valued header types such as ContentEncoding will instead return an empty list value if no values are found. To distinguish the not found case, use try_decode instead.

Source

fn try_decode<H>(&self) -> Option<Result<H>>
where H: StandardHeader,

Decode and return Header type H or Error::Header if found, or return None if not found.

This variant will return Option::None if no header with the associated key (HeaderName) is found in the collection. If the collection does contain such a key, it will return the header type H or Error::Header.

Source

fn encode<H>(&mut self, value: &H)

Encode and write the specified typed header value in the collection.

Uses the Display format of the provided header value to write a single header. This will overwrite any preexisting values with the same key (HeaderName). Use encode_append instead to avoid this.

Source

fn encode_append<H>(&mut self, value: &H)

Encode and append the specified typed header value into the collection.

Uses the Display format of the provided header value to append a single header. If the collection previously had a value for the same key, the additional value is appended to the end.

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.

Implementations on Foreign Types§

Source§

impl TypedHeaders for HeaderMap

Source§

fn decode<H>(&self) -> Result<H>
where H: StandardHeader,

Source§

fn try_decode<H>(&self) -> Option<Result<H>>
where H: StandardHeader,

Source§

fn encode<H>(&mut self, val: &H)

Source§

fn encode_append<H>(&mut self, val: &H)

Implementors§