From acb122c0fcb3757aef2dc31a4757c1215b2917cf Mon Sep 17 00:00:00 2001 From: Stefan Kreutz Date: Sun, 25 Dec 2022 19:41:02 +0100 Subject: Implement size_hint, FusedIterator, ExactIterator --- src/lib.rs | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) (limited to 'src/lib.rs') diff --git a/src/lib.rs b/src/lib.rs index 9c030d0..2d34b1c 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -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) { + let (lower, upper) = self.iter.size_hint(); + let inflight = self.inflight(); + ( + lower.saturating_add(inflight), + upper.and_then(|i| i.checked_add(inflight)), + ) + } +} + +impl FusedIterator for ParallelMap where I: FusedIterator {} + +impl ExactSizeIterator for ParallelMap +where + I: ExactSizeIterator, +{ + fn len(&self) -> usize { + self.iter.len() + self.inflight() + } } /// Calls a given closure when the thread unwinds due to a panic. -- cgit v1.2.3