diff --git a/milli/src/update/new/items_pool.rs b/milli/src/update/new/items_pool.rs index c57bc86f1..92a6d5e64 100644 --- a/milli/src/update/new/items_pool.rs +++ b/milli/src/update/new/items_pool.rs @@ -1,18 +1,21 @@ +use std::sync::Arc; + use crossbeam_channel::{Receiver, Sender, TryRecvError}; use rayon::iter::{MapInit, ParallelIterator}; pub trait ParallelIteratorExt: ParallelIterator { + /// A method on a parallel iterator to map fn try_map_try_init( self, init: INIT, map_op: F, ) -> MapInit< Self, - impl Fn() -> Result> + Sync + Send + Clone, - impl Fn(&mut Result>, Self::Item) -> Result> + Sync + Send + Clone, + impl Fn() -> Result> + Sync + Send + Clone, + impl Fn(&mut Result>, Self::Item) -> Result> + Sync + Send + Clone, > where - E: Send, + E: Send + Sync, F: Fn(&mut T, Self::Item) -> Result + Sync + Send + Clone, INIT: Fn() -> Result + Sync + Send + Clone, R: Send, @@ -20,11 +23,11 @@ pub trait ParallelIteratorExt: ParallelIterator { self.map_init( move || match init() { Ok(t) => Ok(t), - Err(err) => Err(Some(err)), + Err(err) => Err(Arc::new(err)), }, move |maybe_t, item| match maybe_t { - Ok(t) => map_op(t, item).map_err(Some), - Err(maybe_err) => Err(maybe_err.take()), + Ok(t) => map_op(t, item).map_err(Arc::new), + Err(maybe_err) => Err(maybe_err.clone()), }, ) }