@@ -16,7 +16,8 @@ pub struct Chunks<S>
1616{
1717 items : Vec < S :: Item > ,
1818 err : Option < S :: Error > ,
19- stream : Fuse < S >
19+ stream : Fuse < S > ,
20+ cap : usize , // https://github.com/rust-lang-nursery/futures-rs/issues/1475
2021}
2122
2223pub fn new < S > ( s : S , capacity : usize ) -> Chunks < S >
@@ -28,6 +29,7 @@ pub fn new<S>(s: S, capacity: usize) -> Chunks<S>
2829 items : Vec :: with_capacity ( capacity) ,
2930 err : None ,
3031 stream : super :: fuse:: new ( s) ,
32+ cap : capacity,
3133 }
3234}
3335
@@ -54,7 +56,7 @@ impl<S> ::sink::Sink for Chunks<S>
5456
5557impl < S > Chunks < S > where S : Stream {
5658 fn take ( & mut self ) -> Vec < S :: Item > {
57- let cap = self . items . capacity ( ) ;
59+ let cap = self . cap ;
5860 mem:: replace ( & mut self . items , Vec :: with_capacity ( cap) )
5961 }
6062
@@ -93,7 +95,6 @@ impl<S> Stream for Chunks<S>
9395 return Err ( err)
9496 }
9597
96- let cap = self . items . capacity ( ) ;
9798 loop {
9899 match self . stream . poll ( ) {
99100 Ok ( Async :: NotReady ) => return Ok ( Async :: NotReady ) ,
@@ -103,7 +104,7 @@ impl<S> Stream for Chunks<S>
103104 // the full one.
104105 Ok ( Async :: Ready ( Some ( item) ) ) => {
105106 self . items . push ( item) ;
106- if self . items . len ( ) >= cap {
107+ if self . items . len ( ) >= self . cap {
107108 return Ok ( Some ( self . take ( ) ) . into ( ) )
108109 }
109110 }
0 commit comments