Add more HttpTryFrom for HeaderName

This commit is contained in:
Alex Crichton
2017-07-26 12:22:59 -07:00
parent 87403c300b
commit e1c2d83a12
2 changed files with 18 additions and 3 deletions
+17 -2
View File
@@ -1,3 +1,4 @@
use HttpTryFrom;
use byte_str::ByteStr;
use bytes::{Bytes, BytesMut};
@@ -7,7 +8,6 @@ use std::hash::{Hash, Hasher};
use std::str::FromStr;
use std::error::Error;
use ::convert::HttpTryFrom;
/// Represents an HTTP header field name
///
/// Header field names identify the header. Header sets may include multiple
@@ -1540,6 +1540,22 @@ impl From<HeaderName> for Bytes {
}
}
impl<'a> HttpTryFrom<&'a str> for HeaderName {
type Error = InvalidHeaderName;
#[inline]
fn try_from(s: &'a str) -> Result<Self, Self::Error> {
Self::from_bytes(s.as_bytes())
}
}
impl<'a> HttpTryFrom<&'a [u8]> for HeaderName {
type Error = InvalidHeaderName;
#[inline]
fn try_from(s: &'a [u8]) -> Result<Self, Self::Error> {
Self::from_bytes(s)
}
}
impl HttpTryFrom<Bytes> for HeaderName {
type Error = InvalidHeaderName;
#[inline]
@@ -1548,7 +1564,6 @@ impl HttpTryFrom<Bytes> for HeaderName {
}
}
#[doc(hidden)]
impl From<StandardHeader> for HeaderName {
fn from(src: StandardHeader) -> HeaderName {
+1 -1
View File
@@ -315,7 +315,7 @@ impl HttpTryFrom<Bytes> for HeaderValue {
#[inline]
fn try_from(bytes: Bytes) -> Result<Self, Self::Error> {
HeaderValue::try_from(bytes)
<HeaderValue>::try_from(bytes)
}
}