11use futures_lite:: { io, prelude:: * } ;
22
3+ use std:: fmt:: { self , Debug } ;
34use std:: pin:: Pin ;
45use std:: task:: { Context , Poll } ;
56
67/// 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 > ,
1010}
1111
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 ( )
1518 }
1619}
1720
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+ }
2030
2131/// Trait to signal the requirements for an underlying connection type.
2232pub trait InnerConnection : AsyncRead + AsyncWrite + Send + Sync + Unpin { }
2333impl < T : AsyncRead + AsyncWrite + Send + Sync + Unpin > InnerConnection for T { }
2434
25- impl < Inner : AsyncRead + Unpin > AsyncRead for RawConnection < Inner > {
35+ impl AsyncRead for Connection {
2636 fn poll_read (
2737 mut self : Pin < & mut Self > ,
2838 cx : & mut Context < ' _ > ,
@@ -32,7 +42,7 @@ impl<Inner: AsyncRead + Unpin> AsyncRead for RawConnection<Inner> {
3242 }
3343}
3444
35- impl < Inner : AsyncWrite + Unpin > AsyncWrite for RawConnection < Inner > {
45+ impl AsyncWrite for Connection {
3646 fn poll_write (
3747 mut self : Pin < & mut Self > ,
3848 cx : & mut Context < ' _ > ,
0 commit comments