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 AsRef for HeaderValue #1087

Merged
merged 3 commits into from
Aug 12, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 9 additions & 15 deletions async-nats/src/header.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,21 +231,15 @@ impl fmt::Display for HeaderValue {
}
}

impl From<HeaderValue> for String {
fn from(header: HeaderValue) -> Self {
header.to_string()
}
}

impl From<&HeaderValue> for String {
fn from(header: &HeaderValue) -> Self {
header.to_string()
impl AsRef<[u8]> for HeaderValue {
fn as_ref(&self) -> &[u8] {
self.inner.as_ref()
}
}

impl<'a> From<&'a HeaderValue> for &'a str {
fn from(header: &'a HeaderValue) -> Self {
header.inner.as_str()
impl AsRef<str> for HeaderValue {
fn as_ref(&self) -> &str {
self.as_str()
}
}

Expand Down Expand Up @@ -285,7 +279,7 @@ impl HeaderValue {
}

pub fn as_str(&self) -> &str {
self.into()
self.inner.as_str()
}
}

Expand Down Expand Up @@ -602,10 +596,10 @@ mod tests {

assert_eq!(headers.get("Key").unwrap().to_string(), "value");

let key: String = headers.get("Key").unwrap().into();
let key: String = headers.get("Key").unwrap().as_str().into();
assert_eq!(key, "value".to_string());

let key: String = headers.get("Key").unwrap().to_owned().into();
let key: String = headers.get("Key").unwrap().as_str().to_owned();
assert_eq!(key, "value".to_string());

assert_eq!(headers.get("Key").unwrap().as_str(), "value");
Expand Down