pub trait HttpTryFrom<T>: Sized + Sealed {
    type Error: Into<Error>;
}
Expand description

Private trait for the http crate to have generic methods with fallible conversions.

This trait is similar to the TryFrom trait proposed in the standard library, except this is specialized for the http crate and isn’t intended for general consumption.

This trait cannot be implemented types outside of the http crate, and is only intended for use as a generic bound on methods in the http crate.

Associated Types

Associated error with the conversion this implementation represents.

Implementors

Try to convert a HashMap into a HeaderMap.

Examples

use std::collections::HashMap;
use http::{HttpTryFrom, header::HeaderMap};

let mut map = HashMap::new();
map.insert("X-Custom-Header".to_string(), "my value".to_string());

let headers: HeaderMap = HttpTryFrom::try_from(&map).expect("valid headers");
assert_eq!(headers["X-Custom-Header"], "my value");