1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
use super::{fallible, split, TryStreamItem};
use super::{
Chain, Chunks, Cloned, CollectConsumer, Copied, Enumerate, Filter, FilterMap, FindConsumer,
FlatMap, Flatten, Inspect, Intersperse, Map, MapInit, MapWith, NullConsumer, PanicFuse,
Positions, ReduceConsumer, Reduction, Rev, SequentialAdapter, Skip, SkipAnyWhile, Take,
TakeAnyWhile, Update, WhileSome, Zip, ZipEq,
};
/// Core parallel iterator trait for Moirai's Rayon-style non-indexed subset.
pub trait ParallelIterator: Sized + Send {
/// The type of items yielded by this parallel iterator.
type Item: Send;
/// Drive the `Consumer` protocol over this iterator's items.
///
/// # Concurrency contract
///
/// `drive` executes **sequentially** on the calling thread (recursively
/// splitting the consumer and combining, but consuming both halves inline).
/// A prior fork-join drive fanned the split onto the scheduler via
/// `join_with::<Parallel>` and was reverted: the scheduler scope then parked
/// waiters without helping, so nested drives deadlocked and corrupted the
/// heap. The scope primitive is now nesting-sound (ADR-019: worker-thread
/// scope waiters run work instead of parking), so a parallel drive can be
/// reintroduced against it — tracked as ISSUE-208 (c), a separate slice with
/// a parallelism-asserting test. Until that lands, bulk scheduler-owned
/// parallelism is exposed through `Moirai::for_each_indexed` /
/// `map_reduce_indexed`, whose flat fan-out creates no nested scope-waits.
fn drive<C, R>(self, consumer: C) -> R
where
C: Consumer<Self::Item, Result = R> + Send + Sync,
R: Send;
/// Collect all items sequentially without routing through the consumer protocol.
fn seq_items(self) -> Vec<Self::Item>;
/// Collect a logical window from the sequential item stream.
fn seq_items_window(self, skip: usize, take: Option<usize>) -> Vec<Self::Item> {
let iter = self.seq_items().into_iter().skip(skip);
match take {
Some(count) => iter.take(count).collect(),
None => iter.collect(),
}
}
/// Collect items in reverse logical order.
fn seq_items_reversed(self) -> Vec<Self::Item> {
let mut items = self.seq_items();
items.reverse();
items
}
/// Collect a prefix from the reversed logical item stream.
fn seq_items_reversed_prefix(self, count: usize) -> Vec<Self::Item> {
self.seq_items_reversed().into_iter().take(count).collect()
}
/// Map operation that transforms each element in parallel.
fn map<F, R>(self, map_fn: F) -> Map<Self, F>
where
F: Fn(Self::Item) -> R + Send + Sync + Clone,
R: Send,
{
Map::new(self, map_fn)
}
/// Map operation with cloned per-operation state.
fn map_with<T, F, R>(self, init: T, map_fn: F) -> MapWith<Self, T, F>
where
T: Send + Clone,
F: Fn(&mut T, Self::Item) -> R + Send + Sync + Clone,
R: Send + Sync + 'static,
{
MapWith::new(self, init, map_fn)
}
/// Map operation with lazily initialized state.
fn map_init<Init, T, F, R>(self, init: Init, map_fn: F) -> MapInit<Self, Init, F>
where
Init: Fn() -> T + Send + Sync + Clone,
T: Send,
F: Fn(&mut T, Self::Item) -> R + Send + Sync + Clone,
R: Send + Sync + 'static,
{
MapInit::new(self, init, map_fn)
}
/// Mutate each item by reference and yield the mutated item.
fn update<F>(self, update_fn: F) -> Update<Self, F>
where
F: Fn(&mut Self::Item) + Send + Sync + Clone,
Self::Item: Sync + 'static,
{
Update::new(self, update_fn)
}
/// Filter operation that retains elements matching a predicate.
fn filter<F>(self, filter_fn: F) -> Filter<Self, F>
where
F: Fn(&Self::Item) -> bool + Send + Sync + Clone,
{
Filter::new(self, filter_fn)
}
/// Inspect each element by shared reference without changing the stream.
fn inspect<F>(self, inspect_fn: F) -> Inspect<Self, F>
where
F: Fn(&Self::Item) + Send + Sync + Clone,
Self::Item: Sync,
{
Inspect::new(self, inspect_fn)
}
/// Preserve value semantics while stopping sibling work after panic where applicable.
fn panic_fuse(self) -> PanicFuse<Self>
where
Self::Item: Sync,
{
PanicFuse::new(self)
}
/// Map each element to an optional value and retain present values.
fn filter_map<F, R>(self, filter_map_fn: F) -> FilterMap<Self, F>
where
F: Fn(Self::Item) -> Option<R> + Send + Sync + Clone,
R: Send + Sync + 'static,
{
FilterMap::new(self, filter_map_fn)
}
/// Unwrap a prefix of present values from an optional stream.
fn while_some<T>(self) -> WhileSome<Self>
where
Self: ParallelIterator<Item = Option<T>>,
T: Send + Sync + 'static,
{
WhileSome::new(self)
}
/// Map each element to an iterator and flatten the resulting sequence.
fn flat_map<F, U>(self, flat_map_fn: F) -> FlatMap<Self, F>
where
F: Fn(Self::Item) -> U + Send + Sync + Clone,
U: IntoIterator,
U::Item: Send + Sync + 'static,
{
FlatMap::new(self, flat_map_fn)
}
/// Map each element to a serial iterator and flatten the resulting sequence.
fn flat_map_iter<F, U>(self, flat_map_fn: F) -> FlatMap<Self, F>
where
F: Fn(Self::Item) -> U + Send + Sync + Clone,
U: IntoIterator,
U::Item: Send + Sync + 'static,
{
FlatMap::new(self, flat_map_fn)
}
/// Flatten nested item streams with standard left-to-right semantics.
fn flatten(self) -> Flatten<Self>
where
Self::Item: IntoIterator,
<Self::Item as IntoIterator>::Item: Send + Sync + 'static,
{
Flatten::new(self)
}
/// Flatten nested serial iterators with standard left-to-right semantics.
fn flatten_iter(self) -> Flatten<Self>
where
Self::Item: IntoIterator,
<Self::Item as IntoIterator>::Item: Send + Sync + 'static,
{
Flatten::new(self)
}
/// Pair each element with its zero-based position in the logical sequence.
fn enumerate(self) -> Enumerate<Self>
where
Self::Item: Sync + 'static,
{
Enumerate::new(self)
}
/// Pair elements with another parallel iterator, stopping at the shorter input.
fn zip<J>(self, other: J) -> Zip<Self, J>
where
J: ParallelIterator,
Self::Item: Sync + 'static,
J::Item: Sync + 'static,
{
Zip::new(self, other)
}
/// Pair elements with another parallel iterator and require equal lengths.
fn zip_eq<J>(self, other: J) -> ZipEq<Self, J>
where
J: ParallelIterator,
Self::Item: Sync + 'static,
J::Item: Sync + 'static,
{
ZipEq::new(self, other)
}
/// Retain at most `count` elements from the logical sequence prefix.
fn take(self, count: usize) -> Take<Self>
where
Self::Item: Sync + 'static,
{
Take::new(self, count)
}
/// Retain at most `count` items from this non-indexed deterministic stream.
fn take_any(self, count: usize) -> Take<Self>
where
Self::Item: Sync + 'static,
{
Take::new(self, count)
}
/// Discard `count` elements from the logical sequence prefix.
fn skip(self, count: usize) -> Skip<Self>
where
Self::Item: Sync + 'static,
{
Skip::new(self, count)
}
/// Discard `count` items from this non-indexed deterministic stream.
fn skip_any(self, count: usize) -> Skip<Self>
where
Self::Item: Sync + 'static,
{
Skip::new(self, count)
}
/// Retain this deterministic stream prefix while `predicate` returns `true`.
fn take_any_while<F>(self, predicate: F) -> TakeAnyWhile<Self, F>
where
F: Fn(&Self::Item) -> bool + Send + Sync + Clone,
Self::Item: Sync + 'static,
{
TakeAnyWhile::new(self, predicate)
}
/// Discard this deterministic stream prefix while `predicate` returns `true`.
fn skip_any_while<F>(self, predicate: F) -> SkipAnyWhile<Self, F>
where
F: Fn(&Self::Item) -> bool + Send + Sync + Clone,
Self::Item: Sync + 'static,
{
SkipAnyWhile::new(self, predicate)
}
/// Concatenate this iterator with another iterator of the same item type.
fn chain<J>(self, other: J) -> Chain<Self, J>
where
J: ParallelIterator<Item = Self::Item>,
Self::Item: Sync + 'static,
{
Chain::new(self, other)
}
/// Insert a cloned separator between adjacent logical items.
fn intersperse(self, separator: Self::Item) -> Intersperse<Self>
where
Self::Item: Clone + Sync + 'static,
{
Intersperse::new(self, separator)
}
/// Reverse the logical sequence order.
fn rev(self) -> Rev<Self>
where
Self::Item: Sync + 'static,
{
Rev::new(self)
}
/// Group the logical item stream into non-empty chunks.
fn chunks(self, chunk_size: usize) -> Chunks<Self>
where
Self::Item: Sync + 'static,
{
Chunks::new(self, chunk_size)
}
/// Copy referenced items out of a borrowed parallel stream.
fn copied<'data, T>(self) -> Copied<Self>
where
Self: ParallelIterator<Item = &'data T>,
T: Copy + Send + Sync + 'data + 'static,
{
Copied::new(self)
}
/// Clone referenced items out of a borrowed parallel stream.
fn cloned<'data, T>(self) -> Cloned<Self>
where
Self: ParallelIterator<Item = &'data T>,
T: Clone + Send + Sync + 'data + 'static,
{
Cloned::new(self)
}
/// Reduce operation that combines all elements.
fn reduce<F>(self, reduce_fn: F) -> Option<Self::Item>
where
F: Fn(Self::Item, Self::Item) -> Self::Item + Send + Sync + Clone,
Self::Item: Clone + Sync,
{
let reduction: Reduction<Self::Item, F> = self.drive(ReduceConsumer::new(reduce_fn));
reduction.into_value()
}
/// Fold operation with an initial value.
fn fold<T, F>(self, init: T, fold_fn: F) -> T
where
T: Send + Sync + Clone,
F: Fn(T, Self::Item) -> T + Send + Sync + Clone,
Self::Item: Sync,
{
// A fold function maps `(accumulator, item) -> accumulator` and cannot
// combine two partial accumulators without a separate associative
// operation. Preserve sequential value semantics for this API.
self.drive(CollectConsumer::new())
.into_iter()
.fold(init, fold_fn)
}
/// Collect into a collection.
fn collect<C>(self) -> C
where
C: ParallelExtend<Self::Item> + Default + Send,
{
let mut collection = C::default();
collection.par_extend(self);
collection
}
/// Collect into a list of owned vector segments.
///
/// This bounded terminal mirrors Rayon's public `collect_vec_list` return
/// shape while preserving Moirai's logical item stream as one moved
/// segment. Segment count is not part of the semantic contract; flattening
/// the returned list yields the same logical item sequence as `collect`.
fn collect_vec_list(self) -> std::collections::LinkedList<Vec<Self::Item>> {
let items = self.seq_items();
let mut list = std::collections::LinkedList::new();
if !items.is_empty() {
list.push_back(items);
}
list
}
/// Partition items into two collections while preserving relative order.
fn partition<C, F>(self, predicate: F) -> (C, C)
where
C: FromIterator<Self::Item> + Send,
F: Fn(&Self::Item) -> bool + Send + Sync + Clone,
Self::Item: Sync + 'static,
{
let (left_items, right_items): (Vec<Self::Item>, Vec<Self::Item>) = self
.seq_items()
.into_iter()
.partition(|item| predicate(item));
(
left_items.into_iter().collect(),
right_items.into_iter().collect(),
)
}
/// Split mapped `Either` values into two collections while preserving side-local order.
fn partition_map<A, B, P, L, R>(self, predicate: P) -> (A, B)
where
A: Default + Extend<L> + Send,
B: Default + Extend<R> + Send,
P: Fn(Self::Item) -> split::Either<L, R> + Send + Sync + Clone,
L: Send,
R: Send,
{
split::partition_map(self, predicate)
}
/// Split a stream of pairs into two collections while preserving order.
fn unzip<A, B, FromA, FromB>(self) -> (FromA, FromB)
where
Self: ParallelIterator<Item = (A, B)>,
FromA: Default + Extend<A> + Send,
FromB: Default + Extend<B> + Send,
A: Send,
B: Send,
{
self.seq_items().into_iter().unzip()
}
/// Convert to a sequential iterator.
fn sequential(self) -> SequentialAdapter<Self> {
SequentialAdapter::new(self)
}
/// Count the number of elements.
fn count(self) -> usize
where
Self::Item: Sync,
{
self.drive(CollectConsumer::new()).len()
}
/// Find the first element matching a predicate.
fn find_first<F>(self, predicate: F) -> Option<Self::Item>
where
F: Fn(&Self::Item) -> bool + Send + Sync + Clone,
Self::Item: Sync,
{
self.find_any(predicate)
}
/// Find the last element matching a predicate in the logical stream.
fn find_last<F>(self, predicate: F) -> Option<Self::Item>
where
F: Fn(&Self::Item) -> bool + Send + Sync + Clone,
{
self.seq_items().into_iter().rev().find(predicate)
}
/// Find the first logical index matching a predicate.
fn position_first<F>(self, predicate: F) -> Option<usize>
where
F: Fn(Self::Item) -> bool + Send + Sync + Clone,
{
self.seq_items().into_iter().position(predicate)
}
/// Find any logical index matching a predicate.
fn position_any<F>(self, predicate: F) -> Option<usize>
where
F: Fn(Self::Item) -> bool + Send + Sync + Clone,
{
self.position_first(predicate)
}
/// Find the last logical index matching a predicate.
fn position_last<F>(self, predicate: F) -> Option<usize>
where
F: Fn(Self::Item) -> bool + Send + Sync + Clone,
{
self.seq_items().into_iter().rposition(predicate)
}
/// Return all logical indices whose items match a predicate.
fn positions<F>(self, predicate: F) -> Positions<Self, F>
where
F: Fn(Self::Item) -> bool + Send + Sync + Clone,
{
Positions::new(self, predicate)
}
/// Find and map the first matching element in the logical stream.
fn find_map_first<F, R>(self, map_fn: F) -> Option<R>
where
F: Fn(Self::Item) -> Option<R> + Send + Sync + Clone,
R: Send,
{
self.seq_items().into_iter().find_map(map_fn)
}
/// Find and map any matching element in the logical stream.
fn find_map_any<F, R>(self, map_fn: F) -> Option<R>
where
F: Fn(Self::Item) -> Option<R> + Send + Sync + Clone,
R: Send,
{
self.find_map_first(map_fn)
}
/// Find and map the last matching element in the logical stream.
fn find_map_last<F, R>(self, map_fn: F) -> Option<R>
where
F: Fn(Self::Item) -> Option<R> + Send + Sync + Clone,
R: Send,
{
self.seq_items().into_iter().rev().find_map(map_fn)
}
/// Test if any element matches a predicate.
fn any<F>(self, predicate: F) -> bool
where
F: Fn(&Self::Item) -> bool + Send + Sync + Clone,
Self::Item: Sync,
{
self.find_any(predicate).is_some()
}
/// Test if all elements match a predicate.
fn all<F>(self, predicate: F) -> bool
where
F: Fn(&Self::Item) -> bool + Send + Sync + Clone,
Self::Item: Sync,
{
self.find_any(move |item| !predicate(item)).is_none()
}
/// Apply a function to each element.
fn for_each<F>(self, op: F)
where
F: Fn(Self::Item) + Send + Sync + Clone,
{
self.map(op).drive(NullConsumer::new())
}
/// Apply a function to each element with cloned per-operation state.
fn for_each_with<T, F>(self, init: T, op: F)
where
T: Send + Clone,
F: Fn(&mut T, Self::Item) + Send + Sync + Clone,
{
let mut state = init;
for item in self.seq_items() {
op(&mut state, item);
}
}
/// Apply a function to each element with lazily initialized state.
fn for_each_init<Init, T, F>(self, init: Init, op: F)
where
Init: Fn() -> T + Send + Sync + Clone,
T: Send,
F: Fn(&mut T, Self::Item) + Send + Sync + Clone,
{
let mut state = init();
for item in self.seq_items() {
op(&mut state, item);
}
}
/// Apply a fallible function to each element and stop on the first error.
fn try_for_each<F, E>(self, op: F) -> Result<(), E>
where
F: Fn(Self::Item) -> Result<(), E> + Send + Sync + Clone,
E: Send,
{
for item in self.seq_items() {
op(item)?;
}
Ok(())
}
/// Apply a fallible function to each element with cloned per-operation state.
fn try_for_each_with<T, F, E>(self, init: T, op: F) -> Result<(), E>
where
T: Send + Clone,
F: Fn(&mut T, Self::Item) -> Result<(), E> + Send + Sync + Clone,
E: Send,
{
let mut state = init;
for item in self.seq_items() {
op(&mut state, item)?;
}
Ok(())
}
/// Apply a fallible function to each element with lazily initialized state.
fn try_for_each_init<Init, T, F, E>(self, init: Init, op: F) -> Result<(), E>
where
Init: Fn() -> T + Send + Sync + Clone,
T: Send,
F: Fn(&mut T, Self::Item) -> Result<(), E> + Send + Sync + Clone,
E: Send,
{
let mut state = init();
for item in self.seq_items() {
op(&mut state, item)?;
}
Ok(())
}
/// Reduce with an associative operation.
fn reduce_with<F>(self, reduce_fn: F) -> Option<Self::Item>
where
F: Fn(Self::Item, Self::Item) -> Self::Item + Send + Sync + Clone,
Self::Item: Sync + Clone,
{
let reduction: Reduction<Self::Item, F> = self.drive(ReduceConsumer::new(reduce_fn));
reduction.into_value()
}
/// Reduce a fallible item stream with an identity and associative operation.
fn try_reduce<Identity, F, T, E>(self, identity: Identity, reduce_fn: F) -> Result<T, E>
where
Self::Item: Into<Result<T, E>>,
Identity: Fn() -> T + Send + Sync + Clone,
F: Fn(T, T) -> Result<T, E> + Send + Sync + Clone,
T: Send,
E: Send,
{
let mut accumulator = identity();
for item in self.seq_items() {
accumulator = reduce_fn(accumulator, item.into()?)?;
}
Ok(accumulator)
}
/// Reduce a fallible item stream without an identity value.
fn try_reduce_with<F>(self, reduce_fn: F) -> Option<Self::Item>
where
Self::Item: TryStreamItem,
F: Fn(
<Self::Item as TryStreamItem>::Output,
<Self::Item as TryStreamItem>::Output,
) -> Self::Item
+ Send
+ Sync
+ Clone,
{
fallible::try_reduce_with(self, reduce_fn)
}
/// Sum all items using the standard `Sum` contract for the item stream.
fn sum<S>(self) -> S
where
S: std::iter::Sum<Self::Item> + Send,
{
self.seq_items().into_iter().sum()
}
/// Multiply all items using the standard `Product` contract for the item stream.
fn product<P>(self) -> P
where
P: std::iter::Product<Self::Item> + Send,
{
self.seq_items().into_iter().product()
}
/// Return the minimum item in the logical stream.
fn min(self) -> Option<Self::Item>
where
Self::Item: Ord,
{
self.seq_items().into_iter().min()
}
/// Return the maximum item in the logical stream.
fn max(self) -> Option<Self::Item>
where
Self::Item: Ord,
{
self.seq_items().into_iter().max()
}
/// Return the minimum item according to a comparator.
fn min_by<F>(self, compare: F) -> Option<Self::Item>
where
F: Fn(&Self::Item, &Self::Item) -> std::cmp::Ordering + Send + Sync + Clone,
{
self.seq_items().into_iter().min_by(compare)
}
/// Return the maximum item according to a comparator.
fn max_by<F>(self, compare: F) -> Option<Self::Item>
where
F: Fn(&Self::Item, &Self::Item) -> std::cmp::Ordering + Send + Sync + Clone,
{
self.seq_items().into_iter().max_by(compare)
}
/// Return the minimum item according to an ordered key.
fn min_by_key<K, F>(self, key_fn: F) -> Option<Self::Item>
where
K: Ord,
F: Fn(&Self::Item) -> K + Send + Sync + Clone,
{
self.seq_items().into_iter().min_by_key(key_fn)
}
/// Return the maximum item according to an ordered key.
fn max_by_key<K, F>(self, key_fn: F) -> Option<Self::Item>
where
K: Ord,
F: Fn(&Self::Item) -> K + Send + Sync + Clone,
{
self.seq_items().into_iter().max_by_key(key_fn)
}
/// Find any element matching a predicate.
fn find_any<F>(self, predicate: F) -> Option<Self::Item>
where
F: Fn(&Self::Item) -> bool + Send + Sync + Clone,
Self::Item: Sync,
{
self.drive(FindConsumer::new(predicate))
}
}
/// Consumer trait for parallel iterator operations.
pub trait Consumer<T>: Send + Sync {
type Result: Send;
/// Consume items from a parallel iterator.
fn consume<I>(self, iter: I) -> Self::Result
where
I: ParallelIterator<Item = T>;
/// Split the consumer for parallel processing.
fn split_at(self, index: usize) -> (Self, Self)
where
Self: Sized;
/// Combine results from split consumers.
fn combine(left: Self::Result, right: Self::Result) -> Self::Result;
}
/// Trait for collections that can be extended in parallel.
pub trait ParallelExtend<T>: Send {
/// Extend the collection with items from a parallel iterator.
fn par_extend<I>(&mut self, par_iter: I)
where
I: ParallelIterator<Item = T>;
}
/// Extension trait for collections to create parallel iterators.
pub trait IntoParallelIterator {
type Item: Send;
type Iter: ParallelIterator<Item = Self::Item>;
fn into_par_iter(self) -> Self::Iter;
}
/// Extension trait for collection references to create parallel iterators.
pub trait IntoParallelRefIterator<'data> {
type Item: Send + Sync + 'data;
type Iter: ParallelIterator<Item = Self::Item>;
fn par_iter(&'data self) -> Self::Iter;
}