[][src]Struct hyperx::header::Headers

pub struct Headers { /* fields omitted */ }

A specialized map of typed headers.

This type is only available with the non-default headers feature enabled. The type is preserved for compatibly, but its use is no longer required nor recommended. Consider replacing with http::HeaderMap and its TypedHeaders extension.

Implementations

impl Headers[src]

pub fn new() -> Headers[src]

Creates a new, empty headers map.

pub fn with_capacity(len: usize) -> Headers[src]

Creates a new Headers struct with space reserved for len headers.

pub fn set<H: Header>(&mut self, value: H)[src]

Set a header field to the corresponding value.

The field is determined by the type of the value being set.

pub fn get<H: Header>(&self) -> Option<&H>[src]

Get a reference to the header field's value, if it exists.

pub fn get_mut<H: Header>(&mut self) -> Option<&mut H>[src]

Get a mutable reference to the header field's value, if it exists.

pub fn has<H: Header>(&self) -> bool[src]

Returns a boolean of whether a certain header is in the map.

Example:

headers.set(ContentType::json());
assert!(headers.has::<ContentType>());

pub fn remove<H: Header>(&mut self) -> Option<H>[src]

Removes a header from the map, if one existed. Returns the header, if one has been removed and could be parsed.

Note that this function may return None even though a header was removed. If you want to know whether a header exists, rather rely on has.

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

Notable traits for HeadersItems<'a>

impl<'a> Iterator for HeadersItems<'a> type Item = HeaderView<'a>;
[src]

Returns an iterator over the header fields.

pub fn len(&self) -> usize[src]

Returns the number of headers in the map.

pub fn clear(&mut self)[src]

Remove all headers from the map.

pub fn get_raw(&self, name: &str) -> Option<&Raw>[src]

Access the raw value of a header.

Prefer to use the typed getters instead.

Example:

let raw = headers.get_raw("content-type").unwrap();
assert_eq!(raw, "text/plain");

pub fn set_raw<K: Into<Cow<'static, str>>, V: Into<Raw>>(
    &mut self,
    name: K,
    value: V
)
[src]

Set the raw value of a header, bypassing any typed headers.

Example:

headers.set_raw("content-length", b"1".as_ref());
headers.set_raw("content-length", "2");
headers.set_raw("content-length", "3".to_string());
headers.set_raw("content-length", vec![vec![b'4']]);

pub fn append_raw<K: Into<Cow<'static, str>>, V: Into<Raw>>(
    &mut self,
    name: K,
    value: V
)
[src]

Append a value to raw value of this header.

If a header already contains a value, this will add another line to it.

If a header does not exist for this name, a new one will be created with the value.

Example:

headers.append_raw("x-foo", b"bar".to_vec());
headers.append_raw("x-foo", b"quux".to_vec());

pub fn append_raw_str<V: Into<Raw>>(&mut self, name: &str, value: V)[src]

Alternative to append_raw that avoids an allocation if name already exists as a key.

pub fn remove_raw(&mut self, name: &str)[src]

Remove a header by name.

Trait Implementations

impl Clone for Headers[src]

impl Debug for Headers[src]

impl Default for Headers[src]

impl Display for Headers[src]

impl<'a> Extend<(&'a str, Bytes)> for Headers[src]

impl<'a> Extend<HeaderView<'a>> for Headers[src]

impl<'a> From<&'a HeaderMap<HeaderValue>> for Headers[src]

impl<'a> From<&'a Headers> for HeaderMap[src]

impl From<HeaderMap<HeaderValue>> for Headers[src]

impl From<Headers> for HeaderMap[src]

impl<'a> FromIterator<HeaderView<'a>> for Headers[src]

impl PartialEq<Headers> for Headers[src]

Auto Trait Implementations

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> ToString for T where
    T: Display + ?Sized
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.