feat(lib): implement compatibility with http crate
This commit is contained in:
20
src/uri.rs
20
src/uri.rs
@@ -2,6 +2,9 @@ use std::error::Error as StdError;
|
||||
use std::fmt::{Display, self};
|
||||
use std::str::{self, FromStr};
|
||||
|
||||
#[cfg(feature = "compat")]
|
||||
use http_types;
|
||||
|
||||
use ::common::ByteStr;
|
||||
use bytes::{BufMut, Bytes, BytesMut};
|
||||
|
||||
@@ -315,6 +318,23 @@ impl Display for Uri {
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "compat")]
|
||||
impl From<http_types::Uri> for Uri {
|
||||
fn from(uri: http_types::Uri) -> Uri {
|
||||
uri.to_string().parse()
|
||||
.expect("attempted to convert invalid uri")
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(feature = "compat")]
|
||||
impl From<Uri> for http_types::Uri {
|
||||
fn from(uri: Uri) -> http_types::Uri {
|
||||
let bytes = uri.source.into_bytes();
|
||||
http_types::Uri::from_shared(bytes)
|
||||
.expect("attempted to convert invalid uri")
|
||||
}
|
||||
}
|
||||
|
||||
pub unsafe fn from_utf8_unchecked(slice: Bytes) -> Result<Uri, UriError> {
|
||||
Uri::new(ByteStr::from_utf8_unchecked(slice))
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user