1
1
use crate :: stream:: { IntoStream , Merge } ;
2
2
use futures_core:: Stream ;
3
3
4
- use super :: merge:: tuple:: Merge2 ;
4
+ use super :: { chain :: tuple :: Chain2 , merge:: tuple:: Merge2 , zip :: tuple :: Zip2 , Chain , Zip } ;
5
5
6
6
/// An extension trait for the `Stream` trait.
7
7
pub trait StreamExt : Stream {
@@ -10,6 +10,18 @@ pub trait StreamExt: Stream {
10
10
where
11
11
Self : Stream < Item = T > + Sized ,
12
12
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 > ;
13
25
}
14
26
15
27
impl < S1 > StreamExt for S1
23
35
{
24
36
Merge :: merge ( ( self , other) )
25
37
}
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
+ }
26
56
}
0 commit comments