Skip to content

Commit d2c1424

Browse files
committed
Reduce genericity in FromParallelIterator for Result
1 parent 224287b commit d2c1424

File tree

2 files changed

+12
-6
lines changed

2 files changed

+12
-6
lines changed

src/result.rs

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -100,23 +100,27 @@ where
100100
where
101101
I: IntoParallelIterator<Item = Result<T, E>>,
102102
{
103-
let saved_error = Mutex::new(None);
104-
let collection = par_iter
105-
.into_par_iter()
106-
.map(|item| match item {
103+
fn ok<T, E>(saved: &Mutex<Option<E>>) -> impl Fn(Result<T, E>) -> Option<T> + '_ {
104+
move |item| match item {
107105
Ok(item) => Some(item),
108106
Err(error) => {
109107
// We don't need a blocking `lock()`, as anybody
110108
// else holding the lock will also be writing
111109
// `Some(error)`, and then ours is irrelevant.
112-
if let Ok(mut guard) = saved_error.try_lock() {
110+
if let Ok(mut guard) = saved.try_lock() {
113111
if guard.is_none() {
114112
*guard = Some(error);
115113
}
116114
}
117115
None
118116
}
119-
})
117+
}
118+
}
119+
120+
let saved_error = Mutex::new(None);
121+
let collection = par_iter
122+
.into_par_iter()
123+
.map(ok(&saved_error))
120124
.while_some()
121125
.collect();
122126

tests/issue671.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![type_length_limit = "500000"]
2+
13
extern crate rayon;
24

35
use rayon::prelude::*;

0 commit comments

Comments
 (0)