Trait HeaderMapExtT

Source
pub trait HeaderMapExtT {
Show 18 methods // Required methods fn contains_headerkey(&self, key: impl HeaderKeyT) -> bool; fn get_exact<K>(&self, key: K) -> Option<&HeaderValue> where K: AsHeaderName; fn insert_exact(&mut self, key: HeaderName, value: HeaderValue) -> &mut Self; // Provided methods fn get_ascii<K>(&self, key: K) -> Option<&str> where K: HeaderAsciiKeyT { ... } fn get_bin<K>(&self, key: K) -> Result<Option<Vec<u8>>> where K: HeaderBinaryKeyT { ... } fn get_bin_to_buffer<K>(&self, key: K, buffer: &mut Vec<u8>) -> Result<()> where K: HeaderBinaryKeyT { ... } fn get_bin_struct<K, T>(&self, key: K) -> Result<Option<T>> where K: HeaderBinaryKeyT, T: Message + Default { ... } fn get_bin_struct_or_default<K, T>(&self, key: K) -> Result<T> where K: HeaderBinaryKeyT, T: Message + Default { ... } fn insert_ascii<K, V>( &mut self, key: K, value: V, ) -> Result<&mut Self, InvalidHeaderValue> where K: HeaderAsciiKeyT, V: TryInto<HeaderValue, Error = InvalidHeaderValue> { ... } fn insert_ascii_any<K, V>( &mut self, key: K, value: V, ) -> Result<&mut Self, InvalidHeaderValue> where K: HeaderAsciiKeyT, V: StringExtT { ... } fn insert_ascii_infallible<K, V>(&mut self, key: K, value: V) -> &mut Self where K: HeaderAsciiKeyT, V: TryInto<HeaderValue, Error = Infallible> { ... } fn insert_ascii_static<K>( &mut self, key: K, value: &'static str, ) -> &mut Self where K: HeaderAsciiKeyT { ... } fn insert_bin<K, V>(&mut self, key: K, value: V) -> &mut Self where K: HeaderBinaryKeyT, V: TryInto<HeaderValue, Error = InvalidHeaderValue> { ... } fn insert_bin_any<K, V>(&mut self, key: K, value: V) -> &mut Self where K: HeaderBinaryKeyT, V: Base64EncoderT { ... } fn insert_bin_byte<K, V>(&mut self, key: K, value: V) -> &mut Self where K: HeaderBinaryKeyT, V: AsRef<[u8]> { ... } fn insert_bin_struct<K, V>( &mut self, key: K, value: V, ) -> Result<&mut Self, EncodeError> where K: HeaderBinaryKeyT, V: Message + Default { ... } fn insert_bin_static<K>(&mut self, key: K, value: &'static str) -> &mut Self where K: HeaderBinaryKeyT { ... } fn insert_default(&mut self, key: impl HeaderKeyT) -> &mut Self { ... }
}
Expand description

Trait for extending http::HeaderMap’s methods.

If T implements this trait, &mut T will also implement this trait.

Required Methods§

Source

fn contains_headerkey(&self, key: impl HeaderKeyT) -> bool

Check if key exist, just a bridge to HeaderMap or any else

Source

fn get_exact<K>(&self, key: K) -> Option<&HeaderValue>
where K: AsHeaderName,

Get value with exact type, just a bridge to HeaderMap or any else

Accept any key type that can be converted to HeaderName, see AsHeaderName. It can be HeaderName, &’a HeaderName, &’a str or String.

Source

fn insert_exact(&mut self, key: HeaderName, value: HeaderValue) -> &mut Self

Insert value with exact type, just a bridge to HeaderMap or any else

Provided Methods§

Source

fn get_ascii<K>(&self, key: K) -> Option<&str>
where K: HeaderAsciiKeyT,

Returns a reference to the value associated with the key.

For gRPC Metadata, please use get_bin instead.

Notice: if value contains invalid header value characters(non-ascii), it will be ignored and return None.

Source

fn get_bin<K>(&self, key: K) -> Result<Option<Vec<u8>>>

Returns the decoded base64-encoded value associated with the key, if the key-value pair exists.

§Errors
  • Invalid Base64 string.
Source

fn get_bin_to_buffer<K>(&self, key: K, buffer: &mut Vec<u8>) -> Result<()>

Extend the given buffer with the decoded base64-encoded value associated with the key, if the key-value pair exists.

§Errors
  • Invalid Base64 string.
Source

fn get_bin_struct<K, T>(&self, key: K) -> Result<Option<T>>

Returns the struct decoded from the gRPC metadata binary value, if the key-value pair exists.

§Errors
Source

fn get_bin_struct_or_default<K, T>(&self, key: K) -> Result<T>

Returns the struct decoded from the gRPC metadata binary value, or a default one if the key-value pair does not exist.

§Errors
Source

fn insert_ascii<K, V>( &mut self, key: K, value: V, ) -> Result<&mut Self, InvalidHeaderValue>

Inserts a key-value pair into the inner HeaderMap.

For gRPC Metadata, please use insert_bin instead.

§Errors
Source

fn insert_ascii_any<K, V>( &mut self, key: K, value: V, ) -> Result<&mut Self, InvalidHeaderValue>

Inserts a key-value pair into the inner HeaderMap.

value can be any type that implements StringExtT.

For gRPC Metadata, please use insert_bin instead.

§Errors
Source

fn insert_ascii_infallible<K, V>(&mut self, key: K, value: V) -> &mut Self

Inserts a key-value pair into the inner HeaderMap.

For gRPC Metadata, please use insert_bin instead.

Source

fn insert_ascii_static<K>(&mut self, key: K, value: &'static str) -> &mut Self
where K: HeaderAsciiKeyT,

Inserts a key-value pair into the inner HeaderMap.

For gRPC Metadata, please use insert_bin instead.

Source

fn insert_bin<K, V>(&mut self, key: K, value: V) -> &mut Self

Inserts a key-value pair into the inner HeaderMap.

value should be base64 string.

§Panics

Panic if the value is not a valid header value (for base64 string, it’s not possible).

Source

fn insert_bin_any<K, V>(&mut self, key: K, value: V) -> &mut Self

Inserts a key-value pair into the inner HeaderMap.

value can be any type that implement Base64EncoderT. See [b64_padding::STANDARD_NO_PAD::encode](data), etc for more details.

§Panics

Panic if the value is not a valid header value (it’s not possible unless upstream bug).

Source

fn insert_bin_byte<K, V>(&mut self, key: K, value: V) -> &mut Self
where K: HeaderBinaryKeyT, V: AsRef<[u8]>,

Inserts a key-value pair into the inner HeaderMap.

value can be any type that implement AsRef<u8>.

§Panics

Panic if the value is not a valid header value (it’s not possible unless upstream bug).

Source

fn insert_bin_struct<K, V>( &mut self, key: K, value: V, ) -> Result<&mut Self, EncodeError>

Inserts a key-value pair into the inner HeaderMap.

value can be any type that implement AsRef<u8>.

§Errors
§Panics

Panic if the value is not a valid header value (it’s not possible unless upstream bug).

Source

fn insert_bin_static<K>(&mut self, key: K, value: &'static str) -> &mut Self

Inserts a key-value pair into the inner HeaderMap.

Caller must ensure the value is valid base64 string.

Source

fn insert_default(&mut self, key: impl HeaderKeyT) -> &mut Self

Insert default value of T that implement HeaderKeyT

It’s a no-op if there’s no default value.

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 HeaderMapExtT for HeaderMap

Source§

fn contains_headerkey(&self, key: impl HeaderKeyT) -> bool

Source§

fn get_exact<K>(&self, key: K) -> Option<&HeaderValue>
where K: AsHeaderName,

Source§

fn insert_exact(&mut self, key: HeaderName, value: HeaderValue) -> &mut Self

Source§

impl<T> HeaderMapExtT for &mut T
where T: HeaderMapExtT,

Source§

fn contains_headerkey(&self, key: impl HeaderKeyT) -> bool

Source§

fn get_exact<K>(&self, key: K) -> Option<&HeaderValue>
where K: AsHeaderName,

Source§

fn insert_exact(&mut self, key: HeaderName, value: HeaderValue) -> &mut Self

Implementors§