@@ -7,12 +7,13 @@ use crate::stream::Stream;
77use crate :: task:: { Context , Poll } ;
88
99pin_project ! {
10+ #[ derive( Clone , Debug ) ]
1011 #[ cfg( all( feature = "default" , feature = "unstable" ) ) ]
1112 #[ cfg_attr( feature = "docs" , doc( cfg( unstable) ) ) ]
12- pub struct UnzipFuture <S : Stream , FromA , FromB > {
13+ pub struct UnzipFuture <S , FromA , FromB > {
1314 #[ pin]
1415 stream: S ,
15- res: ( FromA , FromB ) ,
16+ res: Option < ( FromA , FromB ) > ,
1617 }
1718}
1819
@@ -24,30 +25,35 @@ where
2425 pub ( super ) fn new ( stream : S ) -> Self {
2526 UnzipFuture {
2627 stream,
27- res : ( FromA :: default ( ) , FromB :: default ( ) ) ,
28+ res : Some ( ( FromA :: default ( ) , FromB :: default ( ) ) ) ,
2829 }
2930 }
3031}
3132
3233impl < S , A , B , FromA , FromB > Future for UnzipFuture < S , FromA , FromB >
3334where
3435 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 > ,
3738{
3839 type Output = ( FromA , FromB ) ;
3940
4041 fn poll ( self : Pin < & mut Self > , cx : & mut Context < ' _ > ) -> Poll < Self :: Output > {
4142 let mut this = self . project ( ) ;
42- let next = futures_core:: ready!( this. stream. as_mut( ) . poll_next( cx) ) ;
4343
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 ( ) ) ,
4956 }
50- None => Poll :: Ready ( * this. res ) ,
5157 }
5258 }
5359}
0 commit comments