pub struct HEADERS { /* private fields */ }
Methods from Deref<Target = HeaderMap>§
sourcepub fn len(&self) -> usize
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());
sourcepub fn keys_len(&self) -> usize
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());
sourcepub fn is_empty(&self) -> bool
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());
sourcepub fn capacity(&self) -> usize
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());
sourcepub fn get<K>(&self, key: K) -> Option<&T>where
K: AsHeaderName,
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");
sourcepub fn get_all<K>(&self, key: K) -> GetAll<'_, T>where
K: AsHeaderName,
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());
sourcepub fn contains_key<K>(&self, key: K) -> boolwhere
K: AsHeaderName,
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"));
sourcepub fn iter(&self) -> Iter<'_, T>
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);
}
sourcepub fn keys(&self) -> Keys<'_, T>
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);
}
sourcepub fn values(&self) -> Values<'_, T>
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);
}