From 3843240940465f3a299d5949fcf53022c42b220e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Renault?= Date: Thu, 26 Sep 2024 18:43:23 +0200 Subject: [PATCH] Prefer using Ars instead of Options --- milli/src/update/new/items_pool.rs | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) 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()), }, ) }