feat(lib): implement compatibility with http crate

This commit is contained in:
Sam Rijs
2017-09-23 05:07:57 +10:00
committed by Sean McArthur
parent 92595e84a2
commit 0c7d375ba3
17 changed files with 535 additions and 1 deletions

View File

@@ -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))
}