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 {
fn into_client_request(self) -> Result<Request> {
let uri: Uri = self.parse()?;
Ok(Request::get(uri).body(())?)
self.parse::<Uri>()?.into_client_request()
}
}
impl<'a> IntoClientRequest for &'a String {
fn into_client_request(self) -> Result<Request> {
let uri: Uri = self.parse()?;
Ok(Request::get(uri).body(())?)
<&str as IntoClientRequest>::into_client_request(self)
}
}
impl IntoClientRequest for String {
fn into_client_request(self) -> Result<Request> {
let uri: Uri = self.parse()?;
Ok(Request::get(uri).body(())?)
<&str as IntoClientRequest>::into_client_request(&self)
}
}
impl<'a> IntoClientRequest for &'a Uri {
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 {
fn into_client_request(self) -> Result<Request> {
let uri: Uri = self.as_str().parse()?;
Ok(Request::get(uri).body(())?)
self.as_str().into_client_request()
}
}
impl IntoClientRequest for Url {
fn into_client_request(self) -> Result<Request> {
let uri: Uri = self.as_str().parse()?;
Ok(Request::get(uri).body(())?)
self.as_str().into_client_request()
}
}

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

Loading…
Cancel
Save