From 9ccba5c931ac167613bb6acc53a8eda137083df3 Mon Sep 17 00:00:00 2001 From: Jeremiah Senkpiel Date: Tue, 22 Sep 2020 11:07:18 -0700 Subject: [PATCH] hyper: minor code improvements --- src/hyper.rs | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/src/hyper.rs b/src/hyper.rs index 0594b55..084976c 100644 --- a/src/hyper.rs +++ b/src/hyper.rs @@ -13,13 +13,15 @@ use std::io; use std::str::FromStr; use std::sync::Arc; +type HyperRequest = hyper::Request; + // 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::client::ResponseFuture; } impl HyperClientObject for hyper::Client { - fn dyn_request(&self, req: hyper::Request) -> hyper::client::ResponseFuture { + fn dyn_request(&self, req: HyperRequest) -> hyper::client::ResponseFuture { self.request(req) } } @@ -69,9 +71,7 @@ impl HttpClient for HyperClient { } } -struct HyperHttpRequest { - inner: hyper::Request, -} +struct HyperHttpRequest(HyperRequest); impl HyperHttpRequest { async fn try_from(mut value: Request) -> Result { @@ -109,17 +109,15 @@ impl HyperHttpRequest { .uri(uri) .body(body)?; - Ok(HyperHttpRequest { inner: request }) + Ok(HyperHttpRequest(request)) } fn into_inner(self) -> hyper::Request { - self.inner + self.0 } } -struct HttpTypesResponse { - inner: Response, -} +struct HttpTypesResponse(Response); impl HttpTypesResponse { async fn try_from(value: hyper::Response) -> Result { @@ -144,11 +142,11 @@ impl HttpTypesResponse { } res.set_body(body); - Ok(HttpTypesResponse { inner: res }) + Ok(HttpTypesResponse(res)) } fn into_inner(self) -> Response { - self.inner + self.0 } }