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
use rayon::iter::ParallelIterator; pub trait NdarrayIntoParallelIterator { type Iter: ParallelIterator<Item=Self::Item>; type Item: Send; fn into_par_iter(self) -> Self::Iter; } pub trait NdarrayIntoParallelRefIterator<'x> { type Iter: ParallelIterator<Item=Self::Item>; type Item: Send + 'x; fn par_iter(&'x self) -> Self::Iter; } pub trait NdarrayIntoParallelRefMutIterator<'x> { type Iter: ParallelIterator<Item=Self::Item>; type Item: Send + 'x; fn par_iter_mut(&'x mut self) -> Self::Iter; } impl<'data, I: 'data + ?Sized> NdarrayIntoParallelRefIterator<'data> for I where &'data I: NdarrayIntoParallelIterator { type Iter = <&'data I as NdarrayIntoParallelIterator>::Iter; type Item = <&'data I as NdarrayIntoParallelIterator>::Item; fn par_iter(&'data self) -> Self::Iter { self.into_par_iter() } } impl<'data, I: 'data + ?Sized> NdarrayIntoParallelRefMutIterator<'data> for I where &'data mut I: NdarrayIntoParallelIterator { type Iter = <&'data mut I as NdarrayIntoParallelIterator>::Iter; type Item = <&'data mut I as NdarrayIntoParallelIterator>::Item; fn par_iter_mut(&'data mut self) -> Self::Iter { self.into_par_iter() } }