From f496711b2142d2400bca00dd39015c8e90073504 Mon Sep 17 00:00:00 2001 From: Sladuca Date: Tue, 6 Sep 2022 14:55:51 -0400 Subject: [PATCH] add flat_map_iter to maybe_rayon & feature-gate it --- maybe_rayon/src/lib.rs | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/maybe_rayon/src/lib.rs b/maybe_rayon/src/lib.rs index 1a9bd823..b7dddc0e 100644 --- a/maybe_rayon/src/lib.rs +++ b/maybe_rayon/src/lib.rs @@ -1,6 +1,6 @@ #[cfg(not(feature = "parallel"))] use std::{ - iter::{IntoIterator, Iterator}, + iter::{IntoIterator, Iterator, FlatMap}, slice::{Chunks, ChunksExact, ChunksExactMut, ChunksMut}, }; @@ -223,13 +223,22 @@ impl MaybeParChunksMut for [T] { } } +#[cfg(not(feature = "parallel"))] pub trait ParallelIteratorMock { type Item; fn find_any

(self, predicate: P) -> Option where P: Fn(&Self::Item) -> bool + Sync + Send; + + fn flat_map_iter(self, map_op: F) -> FlatMap + where + Self: Sized, + U: IntoIterator, + F: Fn(Self::Item) -> U; + } +#[cfg(not(feature = "parallel"))] impl ParallelIteratorMock for T { type Item = T::Item; @@ -239,6 +248,15 @@ impl ParallelIteratorMock for T { { self.find(predicate) } + + fn flat_map_iter(self, map_op: F) -> FlatMap + where + Self: Sized, + U: IntoIterator, + F: Fn(Self::Item) -> U + { + self.flat_map(map_op) + } } #[cfg(feature = "parallel")]