For context, I'm very new to Rust, and I'm trying to learn the best practices and nuances of it as I go.
I've written this small function that takes a HashMap<String, String> and parses it into a http::HeaderMap.
Any feedback on style, idiomatic inconsistencies and general best practice or code smells is appreciated.
fn build_headers(headers: &HashMap<String, String>) -> HeaderMap {
let mut header_map = HeaderMap::new();
for (key, value) in headers {
let key = match HeaderName::try_from(key) {
Ok(key) => key,
Err(_) => {
eprintln!("Invalid header name: {}", key);
continue
}
};
let value = match value.parse() {
Ok(v) => v,
Err(_) => {
eprintln!("Invalid header value: {}", value);
continue
}
};
header_map.insert(key, value);
}
header_map
}