1
1
//! HTTP/2 client connections
2
2
3
- use std:: error:: Error as StdError ;
3
+ use std:: error:: Error ;
4
4
use std:: fmt;
5
5
use std:: marker:: PhantomData ;
6
6
use std:: sync:: Arc ;
@@ -12,12 +12,10 @@ use tokio::io::{AsyncRead, AsyncWrite};
12
12
use super :: super :: dispatch;
13
13
use crate :: body:: { Body , Incoming as IncomingBody } ;
14
14
use crate :: common:: time:: Time ;
15
- use crate :: common:: {
16
- exec:: { BoxSendFuture , Exec } ,
17
- task, Future , Pin , Poll ,
18
- } ;
15
+ use crate :: common:: { task, Future , Pin , Poll } ;
19
16
use crate :: proto;
20
- use crate :: rt:: { Executor , Timer } ;
17
+ use crate :: rt:: bounds:: ExecutorClient ;
18
+ use crate :: rt:: Timer ;
21
19
22
20
/// The sender side of an established connection.
23
21
pub struct SendRequest < B > {
@@ -37,20 +35,22 @@ impl<B> Clone for SendRequest<B> {
37
35
/// In most cases, this should just be spawned into an executor, so that it
38
36
/// can process incoming and outgoing messages, notice hangups, and the like.
39
37
#[ must_use = "futures do nothing unless polled" ]
40
- pub struct Connection < T , B >
38
+ pub struct Connection < T , B , E >
41
39
where
42
- T : AsyncRead + AsyncWrite + Send + ' static ,
40
+ T : AsyncRead + AsyncWrite + ' static + Unpin ,
43
41
B : Body + ' static ,
42
+ E : ExecutorClient < B , T > + Unpin ,
43
+ B :: Error : Into < Box < dyn Error + Send + Sync > > ,
44
44
{
45
- inner : ( PhantomData < T > , proto:: h2:: ClientTask < B > ) ,
45
+ inner : ( PhantomData < T > , proto:: h2:: ClientTask < B , E , T > ) ,
46
46
}
47
47
48
48
/// A builder to configure an HTTP connection.
49
49
///
50
50
/// After setting options, the builder is used to create a handshake future.
51
51
#[ derive( Clone , Debug ) ]
52
- pub struct Builder {
53
- pub ( super ) exec : Exec ,
52
+ pub struct Builder < Ex > {
53
+ pub ( super ) exec : Ex ,
54
54
pub ( super ) timer : Time ,
55
55
h2_builder : proto:: h2:: client:: Config ,
56
56
}
@@ -59,13 +59,16 @@ pub struct Builder {
59
59
///
60
60
/// This is a shortcut for `Builder::new().handshake(io)`.
61
61
/// See [`client::conn`](crate::client::conn) for more.
62
- pub async fn handshake < E , T , B > ( exec : E , io : T ) -> crate :: Result < ( SendRequest < B > , Connection < T , B > ) >
62
+ pub async fn handshake < E , T , B > (
63
+ exec : E ,
64
+ io : T ,
65
+ ) -> crate :: Result < ( SendRequest < B > , Connection < T , B , E > ) >
63
66
where
64
- E : Executor < BoxSendFuture > + Send + Sync + ' static ,
65
- T : AsyncRead + AsyncWrite + Unpin + Send + ' static ,
67
+ T : AsyncRead + AsyncWrite + Unpin + ' static ,
66
68
B : Body + ' static ,
67
69
B :: Data : Send ,
68
- B :: Error : Into < Box < dyn StdError + Send + Sync > > ,
70
+ B :: Error : Into < Box < dyn Error + Send + Sync > > ,
71
+ E : ExecutorClient < B , T > + Unpin + Clone ,
69
72
{
70
73
Builder :: new ( exec) . handshake ( io) . await
71
74
}
@@ -188,12 +191,13 @@ impl<B> fmt::Debug for SendRequest<B> {
188
191
189
192
// ===== impl Connection
190
193
191
- impl < T , B > Connection < T , B >
194
+ impl < T , B , E > Connection < T , B , E >
192
195
where
193
- T : AsyncRead + AsyncWrite + Unpin + Send + ' static ,
196
+ T : AsyncRead + AsyncWrite + Unpin + ' static ,
194
197
B : Body + Unpin + Send + ' static ,
195
198
B :: Data : Send ,
196
- B :: Error : Into < Box < dyn StdError + Send + Sync > > ,
199
+ B :: Error : Into < Box < dyn Error + Send + Sync > > ,
200
+ E : ExecutorClient < B , T > + Unpin ,
197
201
{
198
202
/// Returns whether the [extended CONNECT protocol][1] is enabled or not.
199
203
///
@@ -209,22 +213,26 @@ where
209
213
}
210
214
}
211
215
212
- impl < T , B > fmt:: Debug for Connection < T , B >
216
+ impl < T , B , E > fmt:: Debug for Connection < T , B , E >
213
217
where
214
- T : AsyncRead + AsyncWrite + fmt:: Debug + Send + ' static ,
218
+ T : AsyncRead + AsyncWrite + fmt:: Debug + ' static + Unpin ,
215
219
B : Body + ' static ,
220
+ E : ExecutorClient < B , T > + Unpin ,
221
+ B :: Error : Into < Box < dyn Error + Send + Sync > > ,
216
222
{
217
223
fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
218
224
f. debug_struct ( "Connection" ) . finish ( )
219
225
}
220
226
}
221
227
222
- impl < T , B > Future for Connection < T , B >
228
+ impl < T , B , E > Future for Connection < T , B , E >
223
229
where
224
- T : AsyncRead + AsyncWrite + Unpin + Send + ' static ,
225
- B : Body + Send + ' static ,
230
+ T : AsyncRead + AsyncWrite + Unpin + ' static ,
231
+ B : Body + ' static + Unpin ,
226
232
B :: Data : Send ,
227
- B :: Error : Into < Box < dyn StdError + Send + Sync > > ,
233
+ E : Unpin ,
234
+ B :: Error : Into < Box < dyn Error + Send + Sync > > ,
235
+ E : ExecutorClient < B , T > + ' static + Send + Sync + Unpin ,
228
236
{
229
237
type Output = crate :: Result < ( ) > ;
230
238
@@ -239,22 +247,22 @@ where
239
247
240
248
// ===== impl Builder
241
249
242
- impl Builder {
250
+ impl < Ex > Builder < Ex >
251
+ where
252
+ Ex : Clone ,
253
+ {
243
254
/// Creates a new connection builder.
244
255
#[ inline]
245
- pub fn new < E > ( exec : E ) -> Builder
246
- where
247
- E : Executor < BoxSendFuture > + Send + Sync + ' static ,
248
- {
256
+ pub fn new ( exec : Ex ) -> Builder < Ex > {
249
257
Builder {
250
- exec : Exec :: new ( exec ) ,
258
+ exec,
251
259
timer : Time :: Empty ,
252
260
h2_builder : Default :: default ( ) ,
253
261
}
254
262
}
255
263
256
264
/// Provide a timer to execute background HTTP2 tasks.
257
- pub fn timer < M > ( & mut self , timer : M ) -> & mut Builder
265
+ pub fn timer < M > ( & mut self , timer : M ) -> & mut Builder < Ex >
258
266
where
259
267
M : Timer + Send + Sync + ' static ,
260
268
{
@@ -388,12 +396,13 @@ impl Builder {
388
396
pub fn handshake < T , B > (
389
397
& self ,
390
398
io : T ,
391
- ) -> impl Future < Output = crate :: Result < ( SendRequest < B > , Connection < T , B > ) > >
399
+ ) -> impl Future < Output = crate :: Result < ( SendRequest < B > , Connection < T , B , Ex > ) > >
392
400
where
393
- T : AsyncRead + AsyncWrite + Unpin + Send + ' static ,
401
+ T : AsyncRead + AsyncWrite + Unpin + ' static ,
394
402
B : Body + ' static ,
395
403
B :: Data : Send ,
396
- B :: Error : Into < Box < dyn StdError + Send + Sync > > ,
404
+ B :: Error : Into < Box < dyn Error + Send + Sync > > ,
405
+ Ex : ExecutorClient < B , T > + Unpin ,
397
406
{
398
407
let opts = self . clone ( ) ;
399
408
0 commit comments