diff options
author | Stefan Kreutz <mail@skreutz.com> | 2022-12-25 19:41:02 +0100 |
---|---|---|
committer | Stefan Kreutz <mail@skreutz.com> | 2022-12-25 19:43:15 +0100 |
commit | acb122c0fcb3757aef2dc31a4757c1215b2917cf (patch) | |
tree | 26b4a1ecc68fa85bc4b7814804f3bef2bbe706ca /src | |
parent | fe6f896d1a513431c3ddeecd30e5befe81514db5 (diff) | |
download | parseq-acb122c0fcb3757aef2dc31a4757c1215b2917cf.tar |
Implement size_hint, FusedIterator, ExactIterator
Diffstat (limited to 'src')
-rw-r--r-- | src/lib.rs | 22 |
1 files changed, 21 insertions, 1 deletions
@@ -44,7 +44,7 @@ #![forbid(unsafe_code)] #![warn(missing_docs)] -use std::{collections::HashMap, num::NonZeroUsize}; +use std::{collections::HashMap, iter::FusedIterator, num::NonZeroUsize}; use crossbeam_channel::{Receiver, Select, Sender, TryRecvError}; @@ -295,6 +295,26 @@ where } } } + + fn size_hint(&self) -> (usize, Option<usize>) { + let (lower, upper) = self.iter.size_hint(); + let inflight = self.inflight(); + ( + lower.saturating_add(inflight), + upper.and_then(|i| i.checked_add(inflight)), + ) + } +} + +impl<I, B> FusedIterator for ParallelMap<I, B> where I: FusedIterator {} + +impl<I, B> ExactSizeIterator for ParallelMap<I, B> +where + I: ExactSizeIterator, +{ + fn len(&self) -> usize { + self.iter.len() + self.inflight() + } } /// Calls a given closure when the thread unwinds due to a panic. |