diff --git a/ext/crates/maybe-rayon/src/concurrent.rs b/ext/crates/maybe-rayon/src/concurrent.rs index e75355382..1497aecf2 100644 --- a/ext/crates/maybe-rayon/src/concurrent.rs +++ b/ext/crates/maybe-rayon/src/concurrent.rs @@ -14,6 +14,14 @@ pub mod prelude { fn maybe_par_iter_mut(&'data mut self) -> Self::Iter; } + pub type MaybeIterBridge = rayon::iter::IterBridge; + + pub trait MaybeParallelBridge: ParallelBridge { + fn maybe_par_bridge(self) -> MaybeIterBridge { + self.par_bridge() + } + } + // Implementations impl MaybeParallelIterator for I {} @@ -33,6 +41,8 @@ pub mod prelude { self.par_iter_mut() } } + + impl MaybeParallelBridge for I {} } pub fn join(oper_a: A, oper_b: B) -> (RA, RB) diff --git a/ext/crates/maybe-rayon/src/sequential.rs b/ext/crates/maybe-rayon/src/sequential.rs index 7c1d57a75..ab0369ead 100644 --- a/ext/crates/maybe-rayon/src/sequential.rs +++ b/ext/crates/maybe-rayon/src/sequential.rs @@ -15,6 +15,14 @@ pub mod prelude { fn maybe_par_iter_mut(&'data mut self) -> Self::Iter; } + pub struct MaybeIterBridge(Iter); + + pub trait MaybeParallelBridge: Sized { + fn maybe_par_bridge(self) -> MaybeIterBridge { + MaybeIterBridge(self) + } + } + // Implementations impl MaybeParallelIterator for I {} @@ -39,6 +47,16 @@ pub mod prelude { self.into_iter() } } + + impl Iterator for MaybeIterBridge { + type Item = Iter::Item; + + fn next(&mut self) -> Option { + self.0.next() + } + } + + impl MaybeParallelBridge for T {} } #[allow(dead_code)]