-
-
Notifications
You must be signed in to change notification settings - Fork 164
feat(client): add Layer types for client::conn #243
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Conversation
c5b2c47 to
99c075e
Compare
| } | ||
|
|
||
| /// todo | ||
| pub struct Http2Layer<B> { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think that we should be generic over the executor here:
diff --git a/src/client/conn.rs b/src/client/conn.rs
index d510ec3..0ec767b 100644
--- a/src/client/conn.rs
+++ b/src/client/conn.rs
@@ -39,7 +39,7 @@ impl<B> Clone for Http1Layer<B> {
fn clone(&self) -> Self {
Self {
builder: self.builder.clone(),
- _body: self._body.clone(),
+ _body: self._body,
}
}
}
@@ -101,49 +101,69 @@ impl<M: Clone, B> Clone for Http1Connect<M, B> {
Self {
inner: self.inner.clone(),
builder: self.builder.clone(),
- _body: self._body.clone(),
+ _body: self._body,
}
}
}
/// todo
-pub struct Http2Layer<B> {
+pub struct Http2Layer<B, E> {
+ builder: hyper::client::conn::http2::Builder<E>,
_body: PhantomData<fn(B)>,
}
/// todo
-pub fn http2<B>() -> Http2Layer<B> {
- Http2Layer { _body: PhantomData }
+pub fn http2<B, E>(executor: E) -> Http2Layer<B, E>
+where
+ E: Clone,
+{
+ Http2Layer {
+ builder: hyper::client::conn::http2::Builder::new(executor),
+ _body: PhantomData,
+ }
}
-impl<M, B> tower_layer::Layer<M> for Http2Layer<B> {
- type Service = Http2Connect<M, B>;
+impl<M, B, E> tower_layer::Layer<M> for Http2Layer<B, E>
+where
+ E: Clone,
+{
+ type Service = Http2Connect<M, B, E>;
fn layer(&self, inner: M) -> Self::Service {
Http2Connect {
inner,
- builder: hyper::client::conn::http2::Builder::new(crate::rt::TokioExecutor::new()),
+ builder: self.builder.clone(),
_body: self._body,
}
}
}
-impl<B> Clone for Http2Layer<B> {
+impl<B, E: Clone> Clone for Http2Layer<B, E> {
fn clone(&self) -> Self {
Self {
- _body: self._body.clone(),
+ builder: self.builder.clone(),
+ _body: self._body,
+ }
+ }
+}
+
+impl<B, E> From<hyper::client::conn::http2::Builder<E>> for Http2Layer<B, E> {
+ fn from(builder: hyper::client::conn::http2::Builder<E>) -> Self {
+ Self {
+ builder,
+ _body: PhantomData,
}
}
}
/// todo
#[derive(Debug)]
-pub struct Http2Connect<M, B> {
+pub struct Http2Connect<M, B, E> {
inner: M,
- builder: hyper::client::conn::http2::Builder<crate::rt::TokioExecutor>,
+ builder: hyper::client::conn::http2::Builder<E>,
_body: PhantomData<fn(B)>,
}
-impl<M, Dst, B> Service<Dst> for Http2Connect<M, B>
+impl<M, Dst, B, E> Service<Dst> for Http2Connect<M, B, E>
where
M: Service<Dst>,
M::Future: Send + 'static,
@@ -152,6 +172,7 @@ where
B: hyper::body::Body + Unpin + Send + 'static,
B::Data: Send + 'static,
B::Error: Into<BoxError>,
+ E: hyper::rt::bounds::Http2ClientConnExec<B, M::Response> + Unpin + Clone + Send + 'static,
{
type Response = Http2ClientService<B>;
type Error = BoxError;
@@ -179,12 +200,12 @@ where
}
}
-impl<M: Clone, B> Clone for Http2Connect<M, B> {
+impl<M: Clone, B, E: Clone> Clone for Http2Connect<M, B, E> {
fn clone(&self) -> Self {
Self {
inner: self.inner.clone(),
builder: self.builder.clone(),
- _body: self._body.clone(),
+ _body: self._body,
}
}
}There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah yea definitely, it was something I skipped initially but knew it'd be needed before merging.
| fn clone(&self) -> Self { | ||
| Self { | ||
| builder: self.builder.clone(), | ||
| _body: self._body.clone(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't need to clone phantom data
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
couple of other cases of this elsewhere
src/client/conn.rs
Outdated
|
|
||
| fn call(&mut self, req: Request<B>) -> Self::Future { | ||
| let fut = self.tx.send_request(req); | ||
| Box::pin(async move { Ok(fut.await?) }) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think for here and http1 we can just do Box::pin(fut).
99c075e to
e8d50c9
Compare
e8d50c9 to
1c22e21
Compare
Currently still WIP.
This introduces new types that provide integration of
hyper::client::connwithtower::Layerandtower::Service.