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