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

pub struct Headers { /* fields omitted */ }
Expand description

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

Creates a new, empty headers map.

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

Set a header field to the corresponding value.

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

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

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

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

Example:

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

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.

Returns an iterator over the header fields.

Returns the number of headers in the map.

Remove all headers from the map.

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");

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']]);

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());

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

Remove a header by name.

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Formats the value using the given formatter. Read more

Extends a collection with the contents of an iterator. Read more

🔬 This is a nightly-only experimental API. (extend_one)

Extends a collection with exactly one element.

🔬 This is a nightly-only experimental API. (extend_one)

Reserves capacity in a collection for the given number of additional elements. Read more

Extends a collection with the contents of an iterator. Read more

🔬 This is a nightly-only experimental API. (extend_one)

Extends a collection with exactly one element.

🔬 This is a nightly-only experimental API. (extend_one)

Reserves capacity in a collection for the given number of additional elements. Read more

Performs the conversion.

Performs the conversion.

Performs the conversion.

Performs the conversion.

Creates a value from an iterator. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The resulting type after obtaining ownership.

Creates owned data from borrowed data, usually by cloning. Read more

🔬 This is a nightly-only experimental API. (toowned_clone_into)

recently added

Uses borrowed data to replace owned data, usually by cloning. Read more

Converts the given value to a String. Read more

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.