@@ -170,13 +170,22 @@ impl<W: SendStream> SendStream for &mut W {
170170#[ derive( Debug ) ]
171171pub struct AsyncReadRecvStream < R > ( R ) ;
172172
173+ /// This is a helper trait to work with [`AsyncReadRecvStream`]. If you have an
174+ /// `AsyncRead + Unpin + Send`, you can implement these additional methods and wrap the result
175+ /// in an `AsyncReadRecvStream` to get a `RecvStream` that reads from the underlying `AsyncRead`.
176+ pub trait AsyncReadRecvStreamExtra : Send {
177+ fn inner ( & mut self ) -> & mut ( impl AsyncRead + Unpin + Send ) ;
178+ fn stop ( & mut self , code : VarInt ) -> io:: Result < ( ) > ;
179+ fn id ( & self ) -> u64 ;
180+ }
181+
173182impl < R > AsyncReadRecvStream < R > {
174183 pub fn new ( inner : R ) -> Self {
175184 Self ( inner)
176185 }
177186}
178187
179- impl < R : RecvStreamSpecific > RecvStream for AsyncReadRecvStream < R > {
188+ impl < R : AsyncReadRecvStreamExtra > RecvStream for AsyncReadRecvStream < R > {
180189 async fn recv_bytes ( & mut self , len : usize ) -> io:: Result < Bytes > {
181190 let mut res = vec ! [ 0 ; len] ;
182191 let mut n = 0 ;
@@ -215,18 +224,6 @@ impl<R: RecvStreamSpecific> RecvStream for AsyncReadRecvStream<R> {
215224 }
216225}
217226
218- pub trait RecvStreamSpecific : Send {
219- fn inner ( & mut self ) -> & mut ( impl AsyncRead + Unpin + Send ) ;
220- fn stop ( & mut self , code : VarInt ) -> io:: Result < ( ) > ;
221- fn id ( & self ) -> u64 ;
222- }
223-
224- pub trait SendStreamSpecific : Send {
225- fn inner ( & mut self ) -> & mut ( impl AsyncWrite + Unpin + Send ) ;
226- fn reset ( & mut self , code : VarInt ) -> io:: Result < ( ) > ;
227- fn stopped ( & mut self ) -> impl Future < Output = io:: Result < Option < VarInt > > > + Send ;
228- }
229-
230227impl RecvStream for Bytes {
231228 async fn recv_bytes ( & mut self , len : usize ) -> io:: Result < Bytes > {
232229 let n = len. min ( self . len ( ) ) ;
@@ -267,19 +264,31 @@ impl RecvStream for Bytes {
267264#[ derive( Debug , Clone ) ]
268265pub struct AsyncWriteSendStream < W > ( W ) ;
269266
270- impl < W : SendStreamSpecific > AsyncWriteSendStream < W > {
267+ /// This is a helper trait to work with [`AsyncWriteSendStream`].
268+ ///
269+ /// If you have an `AsyncWrite + Unpin + Send`, you can implement these additional
270+ /// methods and wrap the result in an `AsyncWriteSendStream` to get a `SendStream`
271+ /// that writes to the underlying `AsyncWrite`.
272+ pub trait AsyncWriteSendStreamExtra : Send {
273+ fn inner ( & mut self ) -> & mut ( impl AsyncWrite + Unpin + Send ) ;
274+ fn reset ( & mut self , code : VarInt ) -> io:: Result < ( ) > ;
275+ fn stopped ( & mut self ) -> impl Future < Output = io:: Result < Option < VarInt > > > + Send ;
276+ fn id ( & self ) -> u64 ;
277+ }
278+
279+ impl < W : AsyncWriteSendStreamExtra > AsyncWriteSendStream < W > {
271280 pub fn new ( inner : W ) -> Self {
272281 Self ( inner)
273282 }
274283}
275284
276- impl < W : SendStreamSpecific > AsyncWriteSendStream < W > {
285+ impl < W : AsyncWriteSendStreamExtra > AsyncWriteSendStream < W > {
277286 pub fn into_inner ( self ) -> W {
278287 self . 0
279288 }
280289}
281290
282- impl < W : SendStreamSpecific > SendStream for AsyncWriteSendStream < W > {
291+ impl < W : AsyncWriteSendStreamExtra > SendStream for AsyncWriteSendStream < W > {
283292 async fn send_bytes ( & mut self , bytes : Bytes ) -> io:: Result < ( ) > {
284293 self . 0 . inner ( ) . write_all ( & bytes) . await
285294 }
@@ -303,7 +312,7 @@ impl<W: SendStreamSpecific> SendStream for AsyncWriteSendStream<W> {
303312 }
304313
305314 fn id ( & self ) -> u64 {
306- 0
315+ self . 0 . id ( )
307316 }
308317}
309318
0 commit comments