Merge pull request #143 from phimuemue/simpl

Some simplifications
pull/146/head
Daniel Abramov 4 years ago committed by GitHub
commit 96a8499533
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 22
      src/client.rs
  2. 8
      src/protocol/message.rs

@ -198,31 +198,25 @@ pub trait IntoClientRequest {
impl<'a> IntoClientRequest for &'a str { impl<'a> IntoClientRequest for &'a str {
fn into_client_request(self) -> Result<Request> { fn into_client_request(self) -> Result<Request> {
let uri: Uri = self.parse()?; self.parse::<Uri>()?.into_client_request()
Ok(Request::get(uri).body(())?)
} }
} }
impl<'a> IntoClientRequest for &'a String { impl<'a> IntoClientRequest for &'a String {
fn into_client_request(self) -> Result<Request> { fn into_client_request(self) -> Result<Request> {
let uri: Uri = self.parse()?; <&str as IntoClientRequest>::into_client_request(self)
Ok(Request::get(uri).body(())?)
} }
} }
impl IntoClientRequest for String { impl IntoClientRequest for String {
fn into_client_request(self) -> Result<Request> { fn into_client_request(self) -> Result<Request> {
let uri: Uri = self.parse()?; <&str as IntoClientRequest>::into_client_request(&self)
Ok(Request::get(uri).body(())?)
} }
} }
impl<'a> IntoClientRequest for &'a Uri { impl<'a> IntoClientRequest for &'a Uri {
fn into_client_request(self) -> Result<Request> { fn into_client_request(self) -> Result<Request> {
Ok(Request::get(self.clone()).body(())?) self.clone().into_client_request()
} }
} }
@ -234,17 +228,13 @@ impl IntoClientRequest for Uri {
impl<'a> IntoClientRequest for &'a Url { impl<'a> IntoClientRequest for &'a Url {
fn into_client_request(self) -> Result<Request> { fn into_client_request(self) -> Result<Request> {
let uri: Uri = self.as_str().parse()?; self.as_str().into_client_request()
Ok(Request::get(uri).body(())?)
} }
} }
impl IntoClientRequest for Url { impl IntoClientRequest for Url {
fn into_client_request(self) -> Result<Request> { fn into_client_request(self) -> Result<Request> {
let uri: Uri = self.as_str().parse()?; self.as_str().into_client_request()
Ok(Request::get(uri).body(())?)
} }
} }

@ -37,20 +37,16 @@ mod string_collect {
let mut input: &[u8] = tail.as_ref(); let mut input: &[u8] = tail.as_ref();
if let Some(mut incomplete) = self.incomplete.take() { if let Some(mut incomplete) = self.incomplete.take() {
let fin = if let Some((result, rest)) = incomplete.try_complete(input) { if let Some((result, rest)) = incomplete.try_complete(input) {
input = rest; input = rest;
if let Ok(text) = result { if let Ok(text) = result {
self.data.push_str(text); self.data.push_str(text);
} else { } else {
return Err(Error::Utf8); return Err(Error::Utf8);
} }
true
} else { } else {
input = &[]; input = &[];
false self.incomplete = Some(incomplete);
};
if !fin {
self.incomplete = Some(incomplete)
} }
} }

Loading…
Cancel
Save