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
use crate::prelude::*;
use rayon::prelude::*;
impl<T: Send + Sync> VoluntaryServitude<T> {
#[cfg_attr(docs_rs_workaround, doc(cfg(feature = "rayon-traits")))]
#[inline]
pub fn par_extend<I>(&self, par_iter: I)
where
I: IntoParallelIterator<Item = T>,
{
trace!("par_extend()");
par_iter.into_par_iter().for_each(|el| self.append(el));
}
}
#[cfg_attr(docs_rs_workaround, doc(cfg(feature = "rayon-traits")))]
impl<T: Send + Sync> FromParallelIterator<T> for VoluntaryServitude<T> {
#[inline]
fn from_par_iter<I: IntoParallelIterator<Item = T>>(par_iter: I) -> Self {
trace!("from_par_iter()");
let vs = vs![];
par_iter.into_par_iter().for_each(|el| vs.append(el));
vs
}
}
#[cfg_attr(docs_rs_workaround, doc(cfg(feature = "rayon-traits")))]
impl<T: Send + Sync> ParallelExtend<T> for VoluntaryServitude<T> {
#[inline]
fn par_extend<I: IntoParallelIterator<Item = T>>(&mut self, par_iter: I) {
trace!("ParExtend");
VS::par_extend(self, par_iter);
}
}
#[cfg(test)]
mod tests {
use super::*;
use crate::setup_logger;
#[test]
fn par_extend() {
setup_logger();
let vs = vs![1, 2, 3, 4, 5, 6];
let sum: u8 = vs.iter().sum();
vs.par_extend(vec![1, 2, 3, 4, 5, 6]);
assert_eq!(vs.iter().sum::<u8>(), sum * 2);
}
#[test]
fn from_par_iter() {
setup_logger();
let vec = vec![1, 2, 3, 4, 5, 6];
let sum: u8 = vec.iter().sum();
let vs = VS::from_par_iter(vec);
assert_eq!(vs.iter().sum::<u8>(), sum);
}
}