logo
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
use crate::{ArcArray, Array, ArrayView, ArrayViewMut, Dimension};

use super::prelude::IntoParallelIterator;
use super::Parallel;

/// Requires crate feature `rayon`.
impl<'a, A, D> IntoParallelIterator for &'a Array<A, D>
where
    D: Dimension,
    A: Sync,
{
    type Item = &'a A;
    type Iter = Parallel<ArrayView<'a, A, D>>;
    fn into_par_iter(self) -> Self::Iter {
        self.view().into_par_iter()
    }
}

// This is allowed: goes through `.view()`
/// Requires crate feature `rayon`.
impl<'a, A, D> IntoParallelIterator for &'a ArcArray<A, D>
where
    D: Dimension,
    A: Sync,
{
    type Item = &'a A;
    type Iter = Parallel<ArrayView<'a, A, D>>;
    fn into_par_iter(self) -> Self::Iter {
        self.view().into_par_iter()
    }
}

/// Requires crate feature `rayon`.
impl<'a, A, D> IntoParallelIterator for &'a mut Array<A, D>
where
    D: Dimension,
    A: Sync + Send,
{
    type Item = &'a mut A;
    type Iter = Parallel<ArrayViewMut<'a, A, D>>;
    fn into_par_iter(self) -> Self::Iter {
        self.view_mut().into_par_iter()
    }
}

// This is allowed: goes through `.view_mut()`, which is unique access
/// Requires crate feature `rayon`.
impl<'a, A, D> IntoParallelIterator for &'a mut ArcArray<A, D>
where
    D: Dimension,
    A: Sync + Send + Clone,
{
    type Item = &'a mut A;
    type Iter = Parallel<ArrayViewMut<'a, A, D>>;
    fn into_par_iter(self) -> Self::Iter {
        self.view_mut().into_par_iter()
    }
}