11use crate :: stream:: { IntoStream , Merge } ;
22use futures_core:: Stream ;
33
4- use super :: merge:: tuple:: Merge2 ;
4+ use super :: { chain :: tuple :: Chain2 , merge:: tuple:: Merge2 , zip :: tuple :: Zip2 , Chain , Zip } ;
55
66/// An extension trait for the `Stream` trait.
77pub trait StreamExt : Stream {
@@ -10,6 +10,18 @@ pub trait StreamExt: Stream {
1010 where
1111 Self : Stream < Item = T > + Sized ,
1212 S2 : IntoStream < Item = T > ;
13+
14+ /// Takes two streams and creates a new stream over all in sequence
15+ fn chain < T , S2 > ( self , other : S2 ) -> Chain2 < Self , S2 :: IntoStream >
16+ where
17+ Self : Stream < Item = T > + Sized ,
18+ S2 : IntoStream < Item = T > ;
19+
20+ /// ‘Zips up’ multiple streams into a single stream of pairs.
21+ fn zip < T , S2 > ( self , other : S2 ) -> Zip2 < Self , S2 :: IntoStream >
22+ where
23+ Self : Stream < Item = T > + Sized ,
24+ S2 : IntoStream < Item = T > ;
1325}
1426
1527impl < S1 > StreamExt for S1
2335 {
2436 Merge :: merge ( ( self , other) )
2537 }
38+
39+ fn chain < T , S2 > ( self , other : S2 ) -> Chain2 < Self , S2 :: IntoStream >
40+ where
41+ Self : Stream < Item = T > + Sized ,
42+ S2 : IntoStream < Item = T > ,
43+ {
44+ // TODO(yosh): fix the bounds on the tuple impl
45+ Chain :: chain ( ( self , other. into_stream ( ) ) )
46+ }
47+
48+ fn zip < T , S2 > ( self , other : S2 ) -> Zip2 < Self , S2 :: IntoStream >
49+ where
50+ Self : Stream < Item = T > + Sized ,
51+ S2 : IntoStream < Item = T > ,
52+ {
53+ // TODO(yosh): fix the bounds on the tuple impl
54+ Zip :: zip ( ( self , other. into_stream ( ) ) )
55+ }
2656}
0 commit comments