@@ -8,19 +8,44 @@ use std::io::{Read, Write};
88pub trait Stream : Read + Write { }
99impl < S > Stream for S where S : Read + Write { }
1010
11+ /// If you would like to combine an input stream and an output stream into a single
12+ /// stream to talk websockets over then this is the struct for you!
13+ ///
14+ /// This is useful if you want to use different mediums for different directions.
15+ pub struct ReadWritePair < R , W > ( pub R , pub W )
16+ where R : Read ,
17+ W : Write ;
18+
1119#[ cfg( feature="async" ) ]
1220pub mod async {
21+ use std:: io:: { self , Read , Write } ;
22+ use futures:: Poll ;
23+ pub use super :: ReadWritePair ;
1324 pub use tokio_core:: net:: TcpStream ;
1425 pub use tokio_io:: { AsyncWrite , AsyncRead } ;
1526 pub use tokio_io:: io:: { ReadHalf , WriteHalf } ;
1627
1728 pub trait Stream : AsyncRead + AsyncWrite { }
1829 impl < S > Stream for S where S : AsyncRead + AsyncWrite { }
19- // TODO: implement for a pair of async read/write?
30+
31+ impl < R , W > AsyncRead for ReadWritePair < R , W >
32+ where R : AsyncRead ,
33+ W : Write
34+ {
35+ }
36+ impl < R , W > AsyncWrite for ReadWritePair < R , W >
37+ where W : AsyncWrite ,
38+ R : Read
39+ {
40+ fn shutdown ( & mut self ) -> Poll < ( ) , io:: Error > {
41+ self . 1 . shutdown ( )
42+ }
43+ }
2044}
2145
2246#[ cfg( feature="sync" ) ]
2347pub mod sync {
48+ pub use super :: ReadWritePair ;
2449 use std:: io:: { self , Read , Write } ;
2550 use std:: ops:: Deref ;
2651 use std:: fmt:: Arguments ;
@@ -102,14 +127,6 @@ pub mod sync {
102127 }
103128 }
104129
105- /// If you would like to combine an input stream and an output stream into a single
106- /// stream to talk websockets over then this is the struct for you!
107- ///
108- /// This is useful if you want to use different mediums for different directions.
109- pub struct ReadWritePair < R , W > ( pub R , pub W )
110- where R : Read ,
111- W : Write ;
112-
113130 impl < R , W > Read for ReadWritePair < R , W >
114131 where R : Read ,
115132 W : Write
0 commit comments