mirror of
https://github.com/openharmony/third_party_rust_http.git
synced 2026-07-01 20:44:03 -04:00
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:
@@ -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;
|
||||
|
||||
|
||||
@@ -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
@@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user