@@ -16,6 +16,7 @@ use alloc::prelude::v1::*;
16
16
pub struct Chunks < St : Stream > {
17
17
stream : Fuse < St > ,
18
18
items : Vec < St :: Item > ,
19
+ cap : usize , // https://github.com/rust-lang-nursery/futures-rs/issues/1475
19
20
}
20
21
21
22
impl < St : Unpin + Stream > Unpin for Chunks < St > { }
@@ -30,11 +31,12 @@ impl<St: Stream> Chunks<St> where St: Stream {
30
31
Chunks {
31
32
stream : super :: Fuse :: new ( stream) ,
32
33
items : Vec :: with_capacity ( capacity) ,
34
+ cap : capacity,
33
35
}
34
36
}
35
37
36
38
fn take ( mut self : Pin < & mut Self > ) -> Vec < St :: Item > {
37
- let cap = self . items . capacity ( ) ;
39
+ let cap = self . cap ;
38
40
mem:: replace ( self . as_mut ( ) . items ( ) , Vec :: with_capacity ( cap) )
39
41
}
40
42
@@ -69,15 +71,14 @@ impl<St: Stream> Stream for Chunks<St> {
69
71
mut self : Pin < & mut Self > ,
70
72
waker : & Waker ,
71
73
) -> Poll < Option < Self :: Item > > {
72
- let cap = self . items . capacity ( ) ;
73
74
loop {
74
75
match ready ! ( self . as_mut( ) . stream( ) . poll_next( waker) ) {
75
76
// Push the item into the buffer and check whether it is full.
76
77
// If so, replace our buffer with a new and empty one and return
77
78
// the full one.
78
79
Some ( item) => {
79
80
self . as_mut ( ) . items ( ) . push ( item) ;
80
- if self . items . len ( ) >= cap {
81
+ if self . items . len ( ) >= self . cap {
81
82
return Poll :: Ready ( Some ( self . as_mut ( ) . take ( ) ) )
82
83
}
83
84
}
0 commit comments