File tree Expand file tree Collapse file tree 2 files changed +12
-6
lines changed Expand file tree Collapse file tree 2 files changed +12
-6
lines changed Original file line number Diff line number Diff line change @@ -100,23 +100,27 @@ where
100
100
where
101
101
I : IntoParallelIterator < Item = Result < T , E > > ,
102
102
{
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 {
107
105
Ok ( item) => Some ( item) ,
108
106
Err ( error) => {
109
107
// We don't need a blocking `lock()`, as anybody
110
108
// else holding the lock will also be writing
111
109
// `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 ( ) {
113
111
if guard. is_none ( ) {
114
112
* guard = Some ( error) ;
115
113
}
116
114
}
117
115
None
118
116
}
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) )
120
124
. while_some ( )
121
125
. collect ( ) ;
122
126
Original file line number Diff line number Diff line change
1
+ #![ type_length_limit = "500000" ]
2
+
1
3
extern crate rayon;
2
4
3
5
use rayon:: prelude:: * ;
You can’t perform that action at this time.
0 commit comments