Skip to content

Commit 9ccba5c

Browse files
committed
hyper: minor code improvements
1 parent 72b1b72 commit 9ccba5c

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
}
@@ -69,9 +71,7 @@ impl HttpClient for HyperClient {
6971
}
7072
}
7173

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

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

112-
Ok(HyperHttpRequest { inner: request })
112+
Ok(HyperHttpRequest(request))
113113
}
114114

115115
fn into_inner(self) -> hyper::Request<hyper::Body> {
116-
self.inner
116+
self.0
117117
}
118118
}
119119

120-
struct HttpTypesResponse {
121-
inner: Response,
122-
}
120+
struct HttpTypesResponse(Response);
123121

124122
impl HttpTypesResponse {
125123
async fn try_from(value: hyper::Response<hyper::Body>) -> Result<Self, Error> {
@@ -144,11 +142,11 @@ impl HttpTypesResponse {
144142
}
145143

146144
res.set_body(body);
147-
Ok(HttpTypesResponse { inner: res })
145+
Ok(HttpTypesResponse(res))
148146
}
149147

150148
fn into_inner(self) -> Response {
151-
self.inner
149+
self.0
152150
}
153151
}
154152

0 commit comments

Comments
 (0)