Skip to main content

FromHeaders

Trait FromHeaders 

Source
pub trait FromHeaders: Sized {
    type Error: Error + Send + Sync + 'static;

    // Required methods
    fn header_names() -> &'static [&'static str];
    fn from_headers(headers: &Headers) -> Result<Option<Self>, Self::Error>;
}
Expand description

Extract a value from the Headers collection.

The FromHeaders::from_headers() method is usually used implicitly, through Headers::get() or Headers::get_optional().

Required Associated Types§

Source

type Error: Error + Send + Sync + 'static

The error type which can occur when extracting the value from headers.

Required Methods§

Source

fn header_names() -> &'static [&'static str]

Gets a list of the header names that FromHeaders::from_headers expects.

Used by Headers::get() to generate an error if the headers are not present.

Source

fn from_headers(headers: &Headers) -> Result<Option<Self>, Self::Error>

Extracts the value from the provided Headers collection.

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.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§