Add From impl for header map references

This commit is contained in:
SleeplessOne1917 2023-12-24 17:29:22 -05:00
parent f4851b3914
commit f3e7ac2332
2 changed files with 20 additions and 0 deletions

View File

@ -2,6 +2,10 @@
## Unreleased ## Unreleased
### Changed
- Implement `From<&HeaderMap>` for `http::HeaderMap` and vice versa.
## 3.5.0 ## 3.5.0
### Changed ### Changed

View File

@ -643,6 +643,15 @@ impl From<http::HeaderMap> for HeaderMap {
} }
} }
impl<T> From<&T> for HeaderMap
where
T: Into<http::HeaderMap>,
{
fn from(map: &T) -> Self {
map.to_owned().into()
}
}
/// Convert our `HeaderMap` to a `http::HeaderMap`. /// Convert our `HeaderMap` to a `http::HeaderMap`.
impl From<HeaderMap> for http::HeaderMap { impl From<HeaderMap> for http::HeaderMap {
fn from(map: HeaderMap) -> Self { fn from(map: HeaderMap) -> Self {
@ -650,6 +659,13 @@ impl From<HeaderMap> for http::HeaderMap {
} }
} }
/// Convert our `&HeaderMap` to a `http::HeaderMap`.
impl From<&HeaderMap> for http::HeaderMap {
fn from(map: &HeaderMap) -> Self {
map.to_owned().into()
}
}
/// Iterator over removed, owned values with the same associated name. /// Iterator over removed, owned values with the same associated name.
/// ///
/// Returned from methods that remove or replace items. See [`HeaderMap::insert`] /// Returned from methods that remove or replace items. See [`HeaderMap::insert`]