Skip to content

Commit 349d385

Browse files
committed
hyper: minor code improvements
1 parent 181fe18 commit 349d385

File tree

1 file changed

+9
-11
lines changed

1 file changed

+9
-11
lines changed

src/hyper.rs

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,15 @@ use std::io;
1313
use std::str::FromStr;
1414
use std::sync::Arc;
1515

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

2123
impl<C: Clone + Connect + Debug + Send + Sync + 'static> HyperClientObject for hyper::Client<C> {
22-
fn dyn_request(&self, req: hyper::Request<hyper::Body>) -> hyper::client::ResponseFuture {
24+
fn dyn_request(&self, req: HyperRequest) -> hyper::client::ResponseFuture {
2325
self.request(req)
2426
}
2527
}
@@ -70,9 +72,7 @@ impl HttpClient for HyperClient {
7072
}
7173
}
7274

73-
struct HyperHttpRequest {
74-
inner: hyper::Request<hyper::Body>,
75-
}
75+
struct HyperHttpRequest(HyperRequest);
7676

7777
impl HyperHttpRequest {
7878
async fn try_from(mut value: Request) -> Result<Self, Error> {
@@ -110,17 +110,15 @@ impl HyperHttpRequest {
110110
.uri(uri)
111111
.body(body)?;
112112

113-
Ok(HyperHttpRequest { inner: request })
113+
Ok(HyperHttpRequest(request))
114114
}
115115

116116
fn into_inner(self) -> hyper::Request<hyper::Body> {
117-
self.inner
117+
self.0
118118
}
119119
}
120120

121-
struct HttpTypesResponse {
122-
inner: Response,
123-
}
121+
struct HttpTypesResponse(Response);
124122

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

147145
res.set_body(body);
148-
Ok(HttpTypesResponse { inner: res })
146+
Ok(HttpTypesResponse(res))
149147
}
150148

151149
fn into_inner(self) -> Response {
152-
self.inner
150+
self.0
153151
}
154152
}
155153

0 commit comments

Comments
 (0)