1
1
use async_std:: io:: { self , prelude:: * } ;
2
2
3
- use std:: fmt;
4
3
use std:: pin:: Pin ;
5
4
use std:: task:: { Context , Poll } ;
6
5
7
6
/// An upgraded HTTP connection.
8
- pub struct Connection {
9
- inner : Pin < Box < dyn InnerConnection + ' static > > ,
7
+ #[ derive( Debug , Clone ) ]
8
+ pub struct RawConnection < Inner > {
9
+ inner : Inner ,
10
10
}
11
11
12
- pub ( crate ) trait InnerConnection : Read + Write + Send + Sync + Unpin { }
12
+ /// A boxed upgraded HTTP connection.
13
+ pub type Connection = RawConnection < Box < dyn InnerConnection + ' static > > ;
14
+
15
+ /// Trait to signal the requirements for an underlying connection type.
16
+ pub trait InnerConnection : Read + Write + Send + Sync + Unpin { }
13
17
impl < T : Read + Write + Send + Sync + Unpin > InnerConnection for T { }
14
18
15
- impl Read for Connection {
19
+ impl < Inner : Read + Unpin > Read for RawConnection < Inner > {
16
20
fn poll_read (
17
21
mut self : Pin < & mut Self > ,
18
22
cx : & mut Context < ' _ > ,
@@ -22,7 +26,7 @@ impl Read for Connection {
22
26
}
23
27
}
24
28
25
- impl Write for Connection {
29
+ impl < Inner : Write + Unpin > Write for RawConnection < Inner > {
26
30
fn poll_write (
27
31
mut self : Pin < & mut Self > ,
28
32
cx : & mut Context < ' _ > ,
@@ -39,11 +43,3 @@ impl Write for Connection {
39
43
Pin :: new ( & mut self . inner ) . poll_close ( cx)
40
44
}
41
45
}
42
-
43
- impl fmt:: Debug for Connection {
44
- fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
45
- f. debug_struct ( "Connection" )
46
- . field ( "inner" , & "Pin<Box<dyn Inner>>" )
47
- . finish ( )
48
- }
49
- }
0 commit comments