Skip to content

Commit

Permalink
hyper: minor code improvements
Browse files Browse the repository at this point in the history
  • Loading branch information
Fishrock123 committed Sep 22, 2020
1 parent 181fe18 commit 349d385
Showing 1 changed file with 9 additions and 11 deletions.
20 changes: 9 additions & 11 deletions src/hyper.rs
Expand Up @@ -13,13 +13,15 @@ use std::io;
use std::str::FromStr;
use std::sync::Arc;

type HyperRequest = hyper::Request<hyper::Body>;

// Avoid leaking Hyper generics into HttpClient by hiding it behind a dynamic trait object pointer.
trait HyperClientObject: Debug + Send + Sync + 'static {
fn dyn_request(&self, req: hyper::Request<hyper::Body>) -> hyper::client::ResponseFuture;
}

impl<C: Clone + Connect + Debug + Send + Sync + 'static> HyperClientObject for hyper::Client<C> {
fn dyn_request(&self, req: hyper::Request<hyper::Body>) -> hyper::client::ResponseFuture {
fn dyn_request(&self, req: HyperRequest) -> hyper::client::ResponseFuture {
self.request(req)
}
}
Expand Down Expand Up @@ -70,9 +72,7 @@ impl HttpClient for HyperClient {
}
}

struct HyperHttpRequest {
inner: hyper::Request<hyper::Body>,
}
struct HyperHttpRequest(HyperRequest);

impl HyperHttpRequest {
async fn try_from(mut value: Request) -> Result<Self, Error> {
Expand Down Expand Up @@ -110,17 +110,15 @@ impl HyperHttpRequest {
.uri(uri)
.body(body)?;

Ok(HyperHttpRequest { inner: request })
Ok(HyperHttpRequest(request))
}

fn into_inner(self) -> hyper::Request<hyper::Body> {
self.inner
self.0
}
}

struct HttpTypesResponse {
inner: Response,
}
struct HttpTypesResponse(Response);

impl HttpTypesResponse {
async fn try_from(value: hyper::Response<hyper::Body>) -> Result<Self, Error> {
Expand All @@ -145,11 +143,11 @@ impl HttpTypesResponse {
}

res.set_body(body);
Ok(HttpTypesResponse { inner: res })
Ok(HttpTypesResponse(res))
}

fn into_inner(self) -> Response {
self.inner
self.0
}
}

Expand Down

0 comments on commit 349d385

Please sign in to comment.