Struct charisma::utils::HEADERS

source ·
pub struct HEADERS { /* private fields */ }

Methods from Deref<Target = HeaderMap>§

source

pub fn len(&self) -> usize

Returns the number of headers stored in the map.

This number represents the total number of values stored in the map. This number can be greater than or equal to the number of keys stored given that a single key may have more than one associated value.

Examples
let mut map = HeaderMap::new();

assert_eq!(0, map.len());

map.insert(ACCEPT, "text/plain".parse().unwrap());
map.insert(HOST, "localhost".parse().unwrap());

assert_eq!(2, map.len());

map.append(ACCEPT, "text/html".parse().unwrap());

assert_eq!(3, map.len());
source

pub fn keys_len(&self) -> usize

Returns the number of keys stored in the map.

This number will be less than or equal to len() as each key may have more than one associated value.

Examples
let mut map = HeaderMap::new();

assert_eq!(0, map.keys_len());

map.insert(ACCEPT, "text/plain".parse().unwrap());
map.insert(HOST, "localhost".parse().unwrap());

assert_eq!(2, map.keys_len());

map.insert(ACCEPT, "text/html".parse().unwrap());

assert_eq!(2, map.keys_len());
source

pub fn is_empty(&self) -> bool

Returns true if the map contains no elements.

Examples
let mut map = HeaderMap::new();

assert!(map.is_empty());

map.insert(HOST, "hello.world".parse().unwrap());

assert!(!map.is_empty());
source

pub fn capacity(&self) -> usize

Returns the number of headers the map can hold without reallocating.

This number is an approximation as certain usage patterns could cause additional allocations before the returned capacity is filled.

Examples
let mut map = HeaderMap::new();

assert_eq!(0, map.capacity());

map.insert(HOST, "hello.world".parse().unwrap());
assert_eq!(6, map.capacity());
source

pub fn get<K>(&self, key: K) -> Option<&T>where K: AsHeaderName,

Returns a reference to the value associated with the key.

If there are multiple values associated with the key, then the first one is returned. Use get_all to get all values associated with a given key. Returns None if there are no values associated with the key.

Examples
let mut map = HeaderMap::new();
assert!(map.get("host").is_none());

map.insert(HOST, "hello".parse().unwrap());
assert_eq!(map.get(HOST).unwrap(), &"hello");
assert_eq!(map.get("host").unwrap(), &"hello");

map.append(HOST, "world".parse().unwrap());
assert_eq!(map.get("host").unwrap(), &"hello");
source

pub fn get_all<K>(&self, key: K) -> GetAll<'_, T>where K: AsHeaderName,

Returns a view of all values associated with a key.

The returned view does not incur any allocations and allows iterating the values associated with the key. See GetAll for more details. Returns None if there are no values associated with the key.

Examples
let mut map = HeaderMap::new();

map.insert(HOST, "hello".parse().unwrap());
map.append(HOST, "goodbye".parse().unwrap());

let view = map.get_all("host");

let mut iter = view.iter();
assert_eq!(&"hello", iter.next().unwrap());
assert_eq!(&"goodbye", iter.next().unwrap());
assert!(iter.next().is_none());
source

pub fn contains_key<K>(&self, key: K) -> boolwhere K: AsHeaderName,

Returns true if the map contains a value for the specified key.

Examples
let mut map = HeaderMap::new();
assert!(!map.contains_key(HOST));

map.insert(HOST, "world".parse().unwrap());
assert!(map.contains_key("host"));
source

pub fn iter(&self) -> Iter<'_, T>

An iterator visiting all key-value pairs.

The iteration order is arbitrary, but consistent across platforms for the same crate version. Each key will be yielded once per associated value. So, if a key has 3 associated values, it will be yielded 3 times.

Examples
let mut map = HeaderMap::new();

map.insert(HOST, "hello".parse().unwrap());
map.append(HOST, "goodbye".parse().unwrap());
map.insert(CONTENT_LENGTH, "123".parse().unwrap());

for (key, value) in map.iter() {
    println!("{:?}: {:?}", key, value);
}
source

pub fn keys(&self) -> Keys<'_, T>

An iterator visiting all keys.

The iteration order is arbitrary, but consistent across platforms for the same crate version. Each key will be yielded only once even if it has multiple associated values.

Examples
let mut map = HeaderMap::new();

map.insert(HOST, "hello".parse().unwrap());
map.append(HOST, "goodbye".parse().unwrap());
map.insert(CONTENT_LENGTH, "123".parse().unwrap());

for key in map.keys() {
    println!("{:?}", key);
}
source

pub fn values(&self) -> Values<'_, T>

An iterator visiting all values.

The iteration order is arbitrary, but consistent across platforms for the same crate version.

Examples
let mut map = HeaderMap::new();

map.insert(HOST, "hello".parse().unwrap());
map.append(HOST, "goodbye".parse().unwrap());
map.insert(CONTENT_LENGTH, "123".parse().unwrap());

for value in map.values() {
    println!("{:?}", value);
}

Trait Implementations§

source§

impl Deref for HEADERS

§

type Target = HeaderMap<HeaderValue>

The resulting type after dereferencing.
source§

fn deref(&self) -> &HeaderMap

Dereferences the value.
source§

impl LazyStatic for HEADERS

Auto Trait Implementations§

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T> Instrument for T

source§

fn instrument(self, span: Span) -> Instrumented<Self>

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
source§

fn in_current_span(self) -> Instrumented<Self>

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

§

impl<T> Pointable for T

§

const ALIGN: usize = mem::align_of::<T>()

The alignment of pointer.
§

type Init = T

The type for initializers.
§

unsafe fn init(init: <T as Pointable>::Init) -> usize

Initializes a with the given initializer. Read more
§

unsafe fn deref<'a>(ptr: usize) -> &'a T

Dereferences the given pointer. Read more
§

unsafe fn deref_mut<'a>(ptr: usize) -> &'a mut T

Mutably dereferences the given pointer. Read more
§

unsafe fn drop(ptr: usize)

Drops the object pointed to by the given pointer. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

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

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
source§

impl<T> WithSubscriber for T

source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self>where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
source§

fn with_current_subscriber(self) -> WithDispatch<Self>

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more