There already is a generic fallible conversion implemented from &HashMap<_, _> to HeaderMap:
https://docs.rs/http/latest/src/http/header/map.rs.html#2025https://github.com/hyperium/http/blob/b53194720352ef923d5fa662bc52592520e8b3ce/src/header/map.rs#L2068
Hence, your entire function is superfluous:
use http::HeaderMap;
use std::collections::HashMap;
fn main() {
let mut hash_map = HashMap::new();
hash_map.insert("Content-Type".to_string(), "application/json".to_string());
let header_map: HeaderMap = (&hash_map)
.try_into()
.expect("Hash map should contain valid headers.");
dbg!(header_map);
}