Skip to main content
added 42 characters in body
Source Link

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);
}

https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=63e36c4049adf44ccf1adf6f807bf451

There already is a generic fallible conversion implemented from &HashMap<_, _> to HeaderMap: https://docs.rs/http/latest/src/http/header/map.rs.html#2025

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);
}

https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=63e36c4049adf44ccf1adf6f807bf451

There already is a generic fallible conversion implemented from &HashMap<_, _> to HeaderMap: https://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);
}

https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=63e36c4049adf44ccf1adf6f807bf451

typo
Source Link

There already is a generic fallible conversion implementatedimplemented from &HashMap<_, _> to HeaderMap: https://docs.rs/http/latest/src/http/header/map.rs.html#2025

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);
}

https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=63e36c4049adf44ccf1adf6f807bf451

There already is a generic fallible conversion implementated from &HashMap<_, _> to HeaderMap: https://docs.rs/http/latest/src/http/header/map.rs.html#2025

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);
}

https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=63e36c4049adf44ccf1adf6f807bf451

There already is a generic fallible conversion implemented from &HashMap<_, _> to HeaderMap: https://docs.rs/http/latest/src/http/header/map.rs.html#2025

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);
}

https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=63e36c4049adf44ccf1adf6f807bf451

Source Link

There already is a generic fallible conversion implementated from &HashMap<_, _> to HeaderMap: https://docs.rs/http/latest/src/http/header/map.rs.html#2025

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);
}

https://play.rust-lang.org/?version=stable&mode=debug&edition=2024&gist=63e36c4049adf44ccf1adf6f807bf451