Struct HeaderMap

pub struct HeaderMap<T = HeaderValue> { /* private fields */ }

A specialized multimap for header names and values.

Overview

HeaderMap is designed specifically for efficient manipulation of HTTP headers. It supports multiple values per header name and provides specialized APIs for insertion, retrieval, and iteration.

The internal implementation is optimized for common usage patterns in HTTP, and may change across versions. For example, the current implementation uses Robin Hood hashing to store entries compactly and enable high load factors with good performance. However, the collision resolution strategy and storage mechanism are not part of the public API and may be altered in future releases.

Iteration order

Unless otherwise specified, the order in which items are returned by iterators from HeaderMap methods is arbitrary; there is no guaranteed ordering among the elements yielded by such an iterator. Changes to the iteration order are not considered breaking changes, so users must not rely on any incidental order produced by such an iterator. However, for a given crate version, the iteration order will be consistent across all platforms.

Adaptive hashing

HeaderMap uses an adaptive strategy for hashing to maintain fast lookups while resisting hash collision attacks. The default hash function prioritizes performance. In scenarios where high collision rates are detected—typically indicative of denial-of-service attacks—the implementation switches to a more secure, collision-resistant hash function.

Limitations

A HeaderMap can store at most 32,768 entries (header name/value pairs). Attempting to exceed this limit will result in a panic.

Examples

Basic usage

# use http::HeaderMap;
# use http::header::{CONTENT_LENGTH, HOST, LOCATION};
let mut headers = HeaderMap::new();

headers.insert(HOST, "example.com".parse().unwrap());
headers.insert(CONTENT_LENGTH, "123".parse().unwrap());

assert!(headers.contains_key(HOST));
assert!(!headers.contains_key(LOCATION));

assert_eq!(headers[HOST], "example.com");

headers.remove(HOST);

assert!(!headers.contains_key(HOST));

Implementations

impl HeaderMap

fn new() -> Self

Create an empty HeaderMap.

The map will be created without any capacity. This function will not allocate.

Examples

# use http::HeaderMap;
let map = HeaderMap::new();

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

impl<T> HeaderMap<T>

fn with_capacity(capacity: usize) -> HeaderMap<T>

Create an empty HeaderMap with the specified capacity.

The returned map will allocate internal storage in order to hold about capacity elements without reallocating. However, this is a "best effort" as there are usage patterns that could cause additional allocations before capacity headers are stored in the map.

More capacity than requested may be allocated.

Panics

This method panics if capacity exceeds max HeaderMap capacity.

Examples

# use http::HeaderMap;
let map: HeaderMap<u32> = HeaderMap::with_capacity(10);

assert!(map.is_empty());
assert_eq!(12, map.capacity());
fn try_with_capacity(capacity: usize) -> Result<HeaderMap<T>, MaxSizeReached>

Create an empty HeaderMap with the specified capacity.

The returned map will allocate internal storage in order to hold about capacity elements without reallocating. However, this is a "best effort" as there are usage patterns that could cause additional allocations before capacity headers are stored in the map.

More capacity than requested may be allocated.

Errors

This function may return an error if HeaderMap exceeds max capacity

Examples

# use http::HeaderMap;
let map: HeaderMap<u32> = HeaderMap::try_with_capacity(10).unwrap();

assert!(map.is_empty());
assert_eq!(12, map.capacity());
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

# use http::HeaderMap;
# use http::header::{ACCEPT, HOST};
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());
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

# use http::HeaderMap;
# use http::header::{ACCEPT, HOST};
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());
fn is_empty(&self) -> bool

Returns true if the map contains no elements.

Examples

# use http::HeaderMap;
# use http::header::HOST;
let mut map = HeaderMap::new();

assert!(map.is_empty());

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

assert!(!map.is_empty());
fn clear(&mut self)

Clears the map, removing all key-value pairs. Keeps the allocated memory for reuse.

Examples

# use http::HeaderMap;
# use http::header::HOST;
let mut map = HeaderMap::new();
map.insert(HOST, "hello.world".parse().unwrap());

map.clear();
assert!(map.is_empty());
assert!(map.capacity() > 0);
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

# use http::HeaderMap;
# use http::header::HOST;
let mut map = HeaderMap::new();

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

map.insert(HOST, "hello.world".parse().unwrap());
assert_eq!(6, map.capacity());
fn reserve(&mut self, additional: usize)

Reserves capacity for at least additional more headers to be inserted into the HeaderMap.

The header map may reserve more space to avoid frequent reallocations. Like with with_capacity, this will be a "best effort" to avoid allocations until additional more headers are inserted. Certain usage patterns could cause additional allocations before the number is reached.

Panics

Panics if the new allocation size overflows HeaderMap MAX_SIZE.

Examples

# use http::HeaderMap;
# use http::header::HOST;
let mut map = HeaderMap::new();
map.reserve(10);
# map.insert(HOST, "bar".parse().unwrap());
fn try_reserve(&mut self, additional: usize) -> Result<(), MaxSizeReached>

Reserves capacity for at least additional more headers to be inserted into the HeaderMap.

The header map may reserve more space to avoid frequent reallocations. Like with with_capacity, this will be a "best effort" to avoid allocations until additional more headers are inserted. Certain usage patterns could cause additional allocations before the number is reached.

Errors

This method differs from reserve by returning an error instead of panicking if the value is too large.

Examples

# use http::HeaderMap;
# use http::header::HOST;
let mut map = HeaderMap::new();
map.try_reserve(10).unwrap();
# map.try_insert(HOST, "bar".parse().unwrap()).unwrap();
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

# use http::HeaderMap;
# use http::header::HOST;
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");
fn get_mut<K>(&mut self, key: K) -> Option<&mut T>
where
    K: AsHeaderName,

Returns a mutable reference to the value associated with the key.

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

Examples

# use http::HeaderMap;
# use http::header::HOST;
let mut map = HeaderMap::default();
map.insert(HOST, "hello".to_string());
map.get_mut("host").unwrap().push_str("-world");

assert_eq!(map.get(HOST).unwrap(), &"hello-world");
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

# use http::HeaderMap;
# use http::header::HOST;
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());
fn contains_key<K>(&self, key: K) -> bool
where
    K: AsHeaderName,

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

Examples

# use http::HeaderMap;
# use http::header::HOST;
let mut map = HeaderMap::new();
assert!(!map.contains_key(HOST));

map.insert(HOST, "world".parse().unwrap());
assert!(map.contains_key("host"));
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

# use http::HeaderMap;
# use http::header::{CONTENT_LENGTH, HOST};
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);
}
fn iter_mut(&mut self) -> IterMut<'_, T>

An iterator visiting all key-value pairs, with mutable value references.

The iterator 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

# use http::HeaderMap;
# use http::header::{CONTENT_LENGTH, HOST};
let mut map = HeaderMap::default();

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

for (key, value) in map.iter_mut() {
    value.push_str("-boop");
}
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

# use http::HeaderMap;
# use http::header::{CONTENT_LENGTH, HOST};
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);
}
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

# use http::HeaderMap;
# use http::header::{CONTENT_LENGTH, HOST};
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);
}
fn values_mut(&mut self) -> ValuesMut<'_, T>

An iterator visiting all values mutably.

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

Examples

# use http::HeaderMap;
# use http::header::{CONTENT_LENGTH, HOST};
let mut map = HeaderMap::default();

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

for value in map.values_mut() {
    value.push_str("-boop");
}
fn drain(&mut self) -> Drain<'_, T>

Clears the map, returning all entries as an iterator.

The internal memory is kept for reuse.

For each yielded item that has None provided for the HeaderName, then the associated header name is the same as that of the previously yielded item. The first yielded item will have HeaderName set.

Examples

# use http::HeaderMap;
# use http::header::{CONTENT_LENGTH, HOST};
let mut map = HeaderMap::new();

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

let mut drain = map.drain();


assert_eq!(drain.next(), Some((Some(HOST), "hello".parse().unwrap())));
assert_eq!(drain.next(), Some((None, "goodbye".parse().unwrap())));

assert_eq!(drain.next(), Some((Some(CONTENT_LENGTH), "123".parse().unwrap())));

assert_eq!(drain.next(), None);
fn entry<K>(&mut self, key: K) -> Entry<'_, T>
where
    K: IntoHeaderName,

Gets the given key's corresponding entry in the map for in-place manipulation.

Panics

This method panics if capacity exceeds max HeaderMap capacity

Examples

# use http::HeaderMap;
let mut map: HeaderMap<u32> = HeaderMap::default();

let headers = &[
    "content-length",
    "x-hello",
    "Content-Length",
    "x-world",
];

for &header in headers {
    let counter = map.entry(header).or_insert(0);
    *counter += 1;
}

assert_eq!(map["content-length"], 2);
assert_eq!(map["x-hello"], 1);
fn try_entry<K>(&mut self, key: K) -> Result<Entry<'_, T>, InvalidHeaderName>
where
    K: AsHeaderName,

Gets the given key's corresponding entry in the map for in-place manipulation.

Errors

This method differs from entry by allowing types that may not be valid HeaderNames to passed as the key (such as String). If they do not parse as a valid HeaderName, this returns an InvalidHeaderName error.

If reserving space goes over the maximum, this will also return an error. However, to prevent breaking changes to the return type, the error will still say InvalidHeaderName, unlike other try_* methods which return a MaxSizeReached error.

fn insert<K>(&mut self, key: K, val: T) -> Option<T>
where
    K: IntoHeaderName,

Inserts a key-value pair into the map.

If the map did not previously have this key present, then None is returned.

If the map did have this key present, the new value is associated with the key and all previous values are removed. Note that only a single one of the previous values is returned. If there are multiple values that have been previously associated with the key, then the first one is returned. See insert_mult on OccupiedEntry for an API that returns all values.

The key is not updated, though; this matters for types that can be == without being identical.

Panics

This method panics if capacity exceeds max HeaderMap capacity

Examples

# use http::HeaderMap;
# use http::header::HOST;
let mut map = HeaderMap::new();
assert!(map.insert(HOST, "world".parse().unwrap()).is_none());
assert!(!map.is_empty());

let mut prev = map.insert(HOST, "earth".parse().unwrap()).unwrap();
assert_eq!("world", prev);
fn try_insert<K>(&mut self, key: K, val: T) -> Result<Option<T>, MaxSizeReached>
where
    K: IntoHeaderName,

Inserts a key-value pair into the map.

If the map did not previously have this key present, then None is returned.

If the map did have this key present, the new value is associated with the key and all previous values are removed. Note that only a single one of the previous values is returned. If there are multiple values that have been previously associated with the key, then the first one is returned. See insert_mult on OccupiedEntry for an API that returns all values.

The key is not updated, though; this matters for types that can be == without being identical.

Errors

This function may return an error if HeaderMap exceeds max capacity

Examples

# use http::HeaderMap;
# use http::header::HOST;
let mut map = HeaderMap::new();
assert!(map.try_insert(HOST, "world".parse().unwrap()).unwrap().is_none());
assert!(!map.is_empty());

let mut prev = map.try_insert(HOST, "earth".parse().unwrap()).unwrap().unwrap();
assert_eq!("world", prev);
fn append<K>(&mut self, key: K, value: T) -> bool
where
    K: IntoHeaderName,

Inserts a key-value pair into the map.

If the map did not previously have this key present, then false is returned.

If the map did have this key present, the new value is pushed to the end of the list of values currently associated with the key. The key is not updated, though; this matters for types that can be == without being identical.

Panics

This method panics if capacity exceeds max HeaderMap capacity

Examples

# use http::HeaderMap;
# use http::header::HOST;
let mut map = HeaderMap::new();
assert!(map.insert(HOST, "world".parse().unwrap()).is_none());
assert!(!map.is_empty());

map.append(HOST, "earth".parse().unwrap());

let values = map.get_all("host");
let mut i = values.iter();
assert_eq!("world", *i.next().unwrap());
assert_eq!("earth", *i.next().unwrap());
fn try_append<K>(&mut self, key: K, value: T) -> Result<bool, MaxSizeReached>
where
    K: IntoHeaderName,

Inserts a key-value pair into the map.

If the map did not previously have this key present, then false is returned.

If the map did have this key present, the new value is pushed to the end of the list of values currently associated with the key. The key is not updated, though; this matters for types that can be == without being identical.

Errors

This function may return an error if HeaderMap exceeds max capacity

Examples

# use http::HeaderMap;
# use http::header::HOST;
let mut map = HeaderMap::new();
assert!(map.try_insert(HOST, "world".parse().unwrap()).unwrap().is_none());
assert!(!map.is_empty());

map.try_append(HOST, "earth".parse().unwrap()).unwrap();

let values = map.get_all("host");
let mut i = values.iter();
assert_eq!("world", *i.next().unwrap());
assert_eq!("earth", *i.next().unwrap());
fn remove<K>(&mut self, key: K) -> Option<T>
where
    K: AsHeaderName,

Removes a key from the map, returning the value associated with the key.

Returns None if the map does not contain the key. If there are multiple values associated with the key, then the first one is returned. See remove_entry_mult on OccupiedEntry for an API that yields all values.

Examples

# use http::HeaderMap;
# use http::header::HOST;
let mut map = HeaderMap::new();
map.insert(HOST, "hello.world".parse().unwrap());

let prev = map.remove(HOST).unwrap();
assert_eq!("hello.world", prev);

assert!(map.remove(HOST).is_none());

Trait Implementations

impl<'a, K, V, S, T> TryFrom<&'a HashMap<K, V, S>> for HeaderMap<T> where K: Eq + Hash, HeaderName: TryFrom<&'a K>, <HeaderName as TryFrom<&'a K>>::Error: Into<Error>, T: TryFrom<&'a V>, T::Error: Into<Error>,

type Error = Error;
fn try_from(c: &'a HashMap<K, V, S>) -> Result<Self, Self::Error>

impl<K, T> Index<K> for HeaderMap<T> where K: AsHeaderName,

type Output = T;
fn index(&self, index: K) -> &T

Panics

Using the index operator will cause a panic if the header you're querying isn't set.

impl<T> Default for HeaderMap<T>

fn default() -> Self

impl<T> Extend<(HeaderName, T)> for HeaderMap<T>

fn extend<I: IntoIterator<Item = (HeaderName, T)>>(&mut self, iter: I)

impl<T> Extend<(Option<HeaderName>, T)> for HeaderMap<T>

fn extend<I: IntoIterator<Item = (Option<HeaderName>, T)>>(&mut self, iter: I)

Extend a HeaderMap with the contents of another HeaderMap.

This function expects the yielded items to follow the same structure as IntoIter.

Panics

This panics if the first yielded item does not have a HeaderName.

Examples

# use http::header::*;
let mut map = HeaderMap::new();

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

let mut extra = HeaderMap::new();

extra.insert(HOST, "foo.bar".parse().unwrap());
extra.insert(COOKIE, "hello".parse().unwrap());
extra.append(COOKIE, "world".parse().unwrap());

map.extend(extra);

assert_eq!(map["host"], "foo.bar");
assert_eq!(map["accept"], "text/plain");
assert_eq!(map["cookie"], "hello");

let v = map.get_all("host");
assert_eq!(1, v.iter().count());

let v = map.get_all("cookie");
assert_eq!(2, v.iter().count());

impl<T> FromIterator<(HeaderName, T)> for HeaderMap<T>

fn from_iter<I>(iter: I) -> Self
where
    I: IntoIterator<Item = (HeaderName, T)>,

impl<T> IntoIterator for HeaderMap<T>

type Item = (Option<HeaderName>, T);
type IntoIter = IntoIter<T>;
fn into_iter(self) -> IntoIter<T>

Creates a consuming iterator, that is, one that moves keys and values out of the map in arbitrary order. The map cannot be used after calling this.

For each yielded item that has None provided for the HeaderName, then the associated header name is the same as that of the previously yielded item. The first yielded item will have HeaderName set.

Examples

Basic usage.

# use http::header;
# use http::header::*;
let mut map = HeaderMap::new();
map.insert(header::CONTENT_LENGTH, "123".parse().unwrap());
map.insert(header::CONTENT_TYPE, "json".parse().unwrap());

let mut iter = map.into_iter();
assert_eq!(iter.next(), Some((Some(header::CONTENT_LENGTH), "123".parse().unwrap())));
assert_eq!(iter.next(), Some((Some(header::CONTENT_TYPE), "json".parse().unwrap())));
assert!(iter.next().is_none());

Multiple values per key.

# use http::header;
# use http::header::*;
let mut map = HeaderMap::new();

map.append(header::CONTENT_LENGTH, "123".parse().unwrap());
map.append(header::CONTENT_LENGTH, "456".parse().unwrap());

map.append(header::CONTENT_TYPE, "json".parse().unwrap());
map.append(header::CONTENT_TYPE, "html".parse().unwrap());
map.append(header::CONTENT_TYPE, "xml".parse().unwrap());

let mut iter = map.into_iter();

assert_eq!(iter.next(), Some((Some(header::CONTENT_LENGTH), "123".parse().unwrap())));
assert_eq!(iter.next(), Some((None, "456".parse().unwrap())));

assert_eq!(iter.next(), Some((Some(header::CONTENT_TYPE), "json".parse().unwrap())));
assert_eq!(iter.next(), Some((None, "html".parse().unwrap())));
assert_eq!(iter.next(), Some((None, "xml".parse().unwrap())));
assert!(iter.next().is_none());

impl<T: Clone> Clone for HeaderMap<T>

fn clone(&self) -> HeaderMap<T>

impl<T: Debug> Debug for HeaderMap<T>

fn fmt(&self, f: &mut Formatter<'_>) -> Result

impl<T: Eq> Eq for HeaderMap<T>

impl<T: PartialEq> PartialEq for HeaderMap<T>

fn eq(&self, other: &HeaderMap<T>) -> bool

Auto Trait Implementations

impl<T> Freeze for HeaderMap<T> where Vec<Bucket<T>>: Freeze, Vec<ExtraValue<T>>: Freeze,

impl<T> RefUnwindSafe for HeaderMap<T> where Vec<Bucket<T>>: RefUnwindSafe, Vec<ExtraValue<T>>: RefUnwindSafe,

impl<T> Send for HeaderMap<T> where Vec<Bucket<T>>: Send, Vec<ExtraValue<T>>: Send,

impl<T> Sync for HeaderMap<T> where Vec<Bucket<T>>: Sync, Vec<ExtraValue<T>>: Sync,

impl<T> Unpin for HeaderMap<T> where Vec<Bucket<T>>: Unpin, Vec<ExtraValue<T>>: Unpin,

impl<T> UnsafeUnpin for HeaderMap<T> where Vec<Bucket<T>>: UnsafeUnpin, Vec<ExtraValue<T>>: UnsafeUnpin,

impl<T> UnwindSafe for HeaderMap<T> where Vec<Bucket<T>>: UnwindSafe, Vec<ExtraValue<T>>: UnwindSafe,

Blanket Implementations

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

fn type_id(&self) -> TypeId

impl<T> Borrow<T> for HeaderMap<T> where T: ?Sized,

fn borrow(&self) -> &T

impl<T> BorrowMut<T> for HeaderMap<T> where T: ?Sized,

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

impl<T> CloneToUninit for HeaderMap<T> where T: Clone,

unsafe fn clone_to_uninit(&self, dest: *mut u8)

impl<T> From<T> for HeaderMap<T>

fn from(t: T) -> T

Returns the argument unchanged.

impl<T> ToOwned for HeaderMap<T> where T: Clone,

type Owned = T;
fn to_owned(&self) -> T
fn clone_into(&self, target: &mut T)

impl<T, U> Into<U> for HeaderMap<T> where U: From<T>,

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, U> TryFrom<U> for HeaderMap<T> where U: Into<T>,

type Error = never;
fn try_from(value: U) -> Result<T, never>

impl<T, U> TryInto<U> for HeaderMap<T> where U: TryFrom<T>,

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