feat(client): add Layer types for client::conn#243
Draft
seanmonstar wants to merge 2 commits intomasterfrom
Draft
feat(client): add Layer types for client::conn#243seanmonstar wants to merge 2 commits intomasterfrom
seanmonstar wants to merge 2 commits intomasterfrom
Conversation
c5b2c47 to
99c075e
Compare
sjcobb2022
reviewed
Nov 3, 2025
src/client/conn.rs
Outdated
| } | ||
|
|
||
| /// todo | ||
| pub struct Http2Layer<B> { |
There was a problem hiding this comment.
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,
}
}
}
Member
Author
There was a problem hiding this comment.
Ah yea definitely, it was something I skipped initially but knew it'd be needed before merging.
sjcobb2022
reviewed
Nov 3, 2025
| fn clone(&self) -> Self { | ||
| Self { | ||
| builder: self.builder.clone(), | ||
| _body: self._body.clone(), |
There was a problem hiding this comment.
couple of other cases of this elsewhere
sjcobb2022
reviewed
Nov 3, 2025
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.
I think for here and http1 we can just do Box::pin(fut).
e8d50c9 to
1c22e21
Compare
5c2acda to
0be6059
Compare
0be6059 to
e25e757
Compare
da13aed to
ed0a0ff
Compare
ed0a0ff to
c5594c1
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Currently still WIP.
This introduces new types that provide integration of
hyper::client::connwithtower::Layerandtower::Service.