@@ -7,12 +7,13 @@ use crate::stream::Stream;
7
7
use crate :: task:: { Context , Poll } ;
8
8
9
9
pin_project ! {
10
+ #[ derive( Clone , Debug ) ]
10
11
#[ cfg( all( feature = "default" , feature = "unstable" ) ) ]
11
12
#[ cfg_attr( feature = "docs" , doc( cfg( unstable) ) ) ]
12
- pub struct UnzipFuture <S : Stream , FromA , FromB > {
13
+ pub struct UnzipFuture <S , FromA , FromB > {
13
14
#[ pin]
14
15
stream: S ,
15
- res: ( FromA , FromB ) ,
16
+ res: Option < ( FromA , FromB ) > ,
16
17
}
17
18
}
18
19
@@ -24,30 +25,35 @@ where
24
25
pub ( super ) fn new ( stream : S ) -> Self {
25
26
UnzipFuture {
26
27
stream,
27
- res : ( FromA :: default ( ) , FromB :: default ( ) ) ,
28
+ res : Some ( ( FromA :: default ( ) , FromB :: default ( ) ) ) ,
28
29
}
29
30
}
30
31
}
31
32
32
33
impl < S , A , B , FromA , FromB > Future for UnzipFuture < S , FromA , FromB >
33
34
where
34
35
S : Stream < Item = ( A , B ) > ,
35
- FromA : Default + Extend < A > + Copy ,
36
- FromB : Default + Extend < B > + Copy ,
36
+ FromA : Default + Extend < A > ,
37
+ FromB : Default + Extend < B > ,
37
38
{
38
39
type Output = ( FromA , FromB ) ;
39
40
40
41
fn poll ( self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Self :: Output > {
41
42
let mut this = self . project ( ) ;
42
- let next = futures_core:: ready!( this. stream. as_mut( ) . poll_next( cx) ) ;
43
43
44
- match next {
45
- Some ( ( a, b) ) => {
46
- this. res . 0 . extend ( Some ( a) ) ;
47
- this. res . 1 . extend ( Some ( b) ) ;
48
- Poll :: Pending
44
+ loop {
45
+ let next = futures_core:: ready!( this. stream. as_mut( ) . poll_next( cx) ) ;
46
+
47
+ match next {
48
+ Some ( ( a, b) ) => {
49
+ let mut res = this. res . take ( ) . unwrap ( ) ;
50
+ res. 0 . extend ( Some ( a) ) ;
51
+ res. 1 . extend ( Some ( b) ) ;
52
+
53
+ * this. res = Some ( res) ;
54
+ }
55
+ None => return Poll :: Ready ( this. res . take ( ) . unwrap ( ) ) ,
49
56
}
50
- None => Poll :: Ready ( * this. res ) ,
51
57
}
52
58
}
53
59
}
0 commit comments