@@ -107,11 +107,19 @@ where
107
107
}
108
108
109
109
fn size_hint ( & self ) -> ( usize , Option < usize > ) {
110
- let buf_len = T :: buffer_len ( & self . buf ) ;
111
- let ( mut low, mut hi) = self . iter . size_hint ( ) ;
112
- low = add_then_div ( low, buf_len, T :: num_items ( ) ) . unwrap_or ( usize:: MAX ) ;
113
- hi = hi. and_then ( |elt| add_then_div ( elt, buf_len, T :: num_items ( ) ) ) ;
114
- ( low, hi)
110
+ // The number of elts we've drawn from the underlying iterator, but have
111
+ // not yet produced as a tuple.
112
+ let buffered = T :: buffer_len ( & self . buf ) ;
113
+ // To that, we must add the size estimates of the underlying iterator.
114
+ let ( mut unbuffered_lo, mut unbuffered_hi) = self . iter . size_hint ( ) ;
115
+ // The total low estimate is the sum of the already-buffered elements,
116
+ // plus the low estimate of remaining unbuffered elements, divided by
117
+ // the tuple size.
118
+ let total_lo = add_then_div ( unbuffered_lo, buffered, T :: num_items ( ) ) . unwrap_or ( usize:: MAX ) ;
119
+ // And likewise for the total high estimate, but using the high estimate
120
+ // of the remaining unbuffered elements.
121
+ let total_hi = unbuffered_hi. and_then ( |hi| add_then_div ( hi, buffered, T :: num_items ( ) ) ) ;
122
+ ( total_lo, total_hi)
115
123
}
116
124
}
117
125
0 commit comments