feat(lib): remove extern Url type usage

BREAKING CHANGE: The `Url` type is no longer used. Any instance in the
  `Client` API has had it replaced with `hyper::Uri`.

  This also means `Error::Uri` has changed types to
  `hyper::error::UriError`.

  The type `hyper::header::parsing::HTTP_VALUE` has been made private,
  as an implementation detail. The function `http_percent_encoding`
  should be used instead.
This commit is contained in:
Sean McArthur
2017-03-21 10:35:31 -07:00
parent e81184e53c
commit 4fb7e6ebc6
12 changed files with 192 additions and 155 deletions

View File

@@ -61,7 +61,7 @@ impl Http1Transaction for ServerTransaction {
let path = unsafe { ByteStr::from_utf8_unchecked(path) };
let subject = RequestLine(
method,
try!(::uri::from_mem_str(path)),
try!(::uri::from_byte_str(path)),
);
headers.extend(HeadersAsBytesIter {

View File

@@ -1,8 +1,9 @@
use std::ops::Deref;
use std::str;
use bytes::Bytes;
#[derive(Debug, Clone, PartialEq, Eq)]
#[derive(Debug, Clone, PartialEq, Eq, Hash)]
pub struct ByteStr(Bytes);
impl ByteStr {
@@ -10,7 +11,35 @@ impl ByteStr {
ByteStr(slice)
}
pub fn from_static(s: &'static str) -> ByteStr {
ByteStr(Bytes::from_static(s.as_bytes()))
}
pub fn slice(&self, from: usize, to: usize) -> ByteStr {
assert!(self.as_str().is_char_boundary(from));
assert!(self.as_str().is_char_boundary(to));
ByteStr(self.0.slice(from, to))
}
pub fn slice_to(&self, idx: usize) -> ByteStr {
assert!(self.as_str().is_char_boundary(idx));
ByteStr(self.0.slice_to(idx))
}
pub fn as_str(&self) -> &str {
unsafe { str::from_utf8_unchecked(self.0.as_ref()) }
}
}
impl Deref for ByteStr {
type Target = str;
fn deref(&self) -> &str {
self.as_str()
}
}
impl<'a> From<&'a str> for ByteStr {
fn from(s: &'a str) -> ByteStr {
ByteStr(Bytes::from(s))
}
}