Add missing TryFrom<String> and TryFrom<Vec<u8>> impls. (#477)

Also fix PathAndQuery's TryFrom<String> impl to not copy the bytes into
a new Bytes.
This commit is contained in:
Arnav Singh
2021-04-21 06:54:31 -07:00
committed by GitHub
parent f7195c92d7
commit 6a91d66523
3 changed files with 36 additions and 1 deletions
+18
View File
@@ -442,6 +442,24 @@ impl<'a> TryFrom<&'a str> for Authority {
}
}
impl TryFrom<Vec<u8>> for Authority {
type Error = InvalidUri;
#[inline]
fn try_from(vec: Vec<u8>) -> Result<Self, Self::Error> {
Authority::from_shared(vec.into())
}
}
impl TryFrom<String> for Authority {
type Error = InvalidUri;
#[inline]
fn try_from(t: String) -> Result<Self, Self::Error> {
Authority::from_shared(t.into())
}
}
impl FromStr for Authority {
type Err = InvalidUri;
+9
View File
@@ -711,6 +711,15 @@ impl TryFrom<String> for Uri {
}
}
impl<'a> TryFrom<Vec<u8>> for Uri {
type Error = InvalidUri;
#[inline]
fn try_from(vec: Vec<u8>) -> Result<Self, Self::Error> {
Uri::from_shared(Bytes::from(vec))
}
}
impl TryFrom<Parts> for Uri {
type Error = InvalidUriParts;
+9 -1
View File
@@ -291,11 +291,19 @@ impl<'a> TryFrom<&'a str> for PathAndQuery {
}
}
impl<'a> TryFrom<Vec<u8>> for PathAndQuery {
type Error = InvalidUri;
#[inline]
fn try_from(vec: Vec<u8>) -> Result<Self, Self::Error> {
PathAndQuery::from_shared(vec.into())
}
}
impl TryFrom<String> for PathAndQuery {
type Error = InvalidUri;
#[inline]
fn try_from(s: String) -> Result<Self, Self::Error> {
TryFrom::try_from(s.as_bytes())
PathAndQuery::from_shared(s.into())
}
}