Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement an easy conversion from HashMap to HeaderMap #325

Closed
lovasoa opened this issue Jul 2, 2019 · 0 comments · Fixed by #326
Closed

Implement an easy conversion from HashMap to HeaderMap #325

lovasoa opened this issue Jul 2, 2019 · 0 comments · Fixed by #326

Comments

@lovasoa
Copy link
Contributor

lovasoa commented Jul 2, 2019

I would be nice to be able to easily convert from a HashMap<String, String> to a HeaderMap. This might be implemented in a generic way with for instance an

impl<COLLECTION, K, V> HttpTryFrom<COLLECTION> for HeaderMap<HeaderValue>
    where
        COLLECTION: IntoIterator<Item=(K,V)>,
        K: AsRef<str>,
        V: AsRef<str>

See : seanmonstar/reqwest#555

What do you think ? Would you accept a pull request implementing that ?

lovasoa added a commit to lovasoa/http that referenced this issue Jul 2, 2019
This allows an easy conversion from HashMap<String,String>
to HeaderMap<HeaderValue>.

Doing this conversion used to be unnecessarily verbose
because of the required mapping and error type conversions.

The implementation is generic:

    impl<COLLECTION, K, V> HttpTryFrom<COLLECTION> for HeaderMap<HeaderValue>
    where
        COLLECTION: IntoIterator<Item=(K, V)>,
        K: AsRef<str>,
        V: AsRef<str>

so it also works for HashMap<HeaderName, String> and for vectors.

Fixes hyperium#325
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant