Skip to content

Commit

Permalink
Tuples::size_hint
Browse files Browse the repository at this point in the history
  • Loading branch information
Philippe-Cholet committed Sep 27, 2023
1 parent 30b583f commit 9f20d49
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/tuple_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,14 @@ where
fn next(&mut self) -> Option<Self::Item> {
T::collect_from_iter(&mut self.iter, &mut self.buf)
}

fn size_hint(&self) -> (usize, Option<usize>) {
let buf_len = T::buffer_len(&self.buf);
let (mut low, mut hi) = self.iter.size_hint();
low = add_then_div(low, buf_len, T::num_items()).unwrap_or(usize::MAX);
hi = hi.and_then(|elt| add_then_div(elt, buf_len, T::num_items()));
(low, hi)
}
}

/// `(n + a) / d` avoiding overflow when possible, returns `None` if it overflows.
Expand Down

0 comments on commit 9f20d49

Please sign in to comment.