mirror of
https://github.com/meilisearch/MeiliSearch
synced 2024-10-30 09:48:49 +01:00
Prefer using Ars instead of Options
This commit is contained in:
parent
8cb5e7437d
commit
3843240940
@ -1,18 +1,21 @@
|
|||||||
|
use std::sync::Arc;
|
||||||
|
|
||||||
use crossbeam_channel::{Receiver, Sender, TryRecvError};
|
use crossbeam_channel::{Receiver, Sender, TryRecvError};
|
||||||
use rayon::iter::{MapInit, ParallelIterator};
|
use rayon::iter::{MapInit, ParallelIterator};
|
||||||
|
|
||||||
pub trait ParallelIteratorExt: ParallelIterator {
|
pub trait ParallelIteratorExt: ParallelIterator {
|
||||||
|
/// A method on a parallel iterator to map
|
||||||
fn try_map_try_init<F, INIT, T, E, R>(
|
fn try_map_try_init<F, INIT, T, E, R>(
|
||||||
self,
|
self,
|
||||||
init: INIT,
|
init: INIT,
|
||||||
map_op: F,
|
map_op: F,
|
||||||
) -> MapInit<
|
) -> MapInit<
|
||||||
Self,
|
Self,
|
||||||
impl Fn() -> Result<T, Option<E>> + Sync + Send + Clone,
|
impl Fn() -> Result<T, Arc<E>> + Sync + Send + Clone,
|
||||||
impl Fn(&mut Result<T, Option<E>>, Self::Item) -> Result<R, Option<E>> + Sync + Send + Clone,
|
impl Fn(&mut Result<T, Arc<E>>, Self::Item) -> Result<R, Arc<E>> + Sync + Send + Clone,
|
||||||
>
|
>
|
||||||
where
|
where
|
||||||
E: Send,
|
E: Send + Sync,
|
||||||
F: Fn(&mut T, Self::Item) -> Result<R, E> + Sync + Send + Clone,
|
F: Fn(&mut T, Self::Item) -> Result<R, E> + Sync + Send + Clone,
|
||||||
INIT: Fn() -> Result<T, E> + Sync + Send + Clone,
|
INIT: Fn() -> Result<T, E> + Sync + Send + Clone,
|
||||||
R: Send,
|
R: Send,
|
||||||
@ -20,11 +23,11 @@ pub trait ParallelIteratorExt: ParallelIterator {
|
|||||||
self.map_init(
|
self.map_init(
|
||||||
move || match init() {
|
move || match init() {
|
||||||
Ok(t) => Ok(t),
|
Ok(t) => Ok(t),
|
||||||
Err(err) => Err(Some(err)),
|
Err(err) => Err(Arc::new(err)),
|
||||||
},
|
},
|
||||||
move |maybe_t, item| match maybe_t {
|
move |maybe_t, item| match maybe_t {
|
||||||
Ok(t) => map_op(t, item).map_err(Some),
|
Ok(t) => map_op(t, item).map_err(Arc::new),
|
||||||
Err(maybe_err) => Err(maybe_err.take()),
|
Err(maybe_err) => Err(maybe_err.clone()),
|
||||||
},
|
},
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user