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
/// Macro for running a function in parallel.
#[macro_export(local_inner_macros)]
macro_rules! run_par {
    (
        $func:expr
    ) => {{
        #[cfg(feature = "std")]
        use rayon::prelude::*;

        #[cfg(feature = "std")]
        #[allow(clippy::redundant_closure_call)]
        let output = rayon::scope(|_| $func());

        #[cfg(not(feature = "std"))]
        let output = $func();

        output
    }};
}

/// Macro for iterating in parallel.
#[macro_export(local_inner_macros)]
macro_rules! iter_par {
    (
        $iter:expr
    ) => {{
        #[cfg(feature = "std")]
        let output = $iter.into_par_iter();

        #[cfg(not(feature = "std"))]
        let output = $iter;

        output
    }};
}

/// Macro for iterating over a range in parallel.
#[macro_export(local_inner_macros)]
macro_rules! iter_range_par {
    (
        $start:expr, $end:expr
    ) => {{
        #[cfg(feature = "std")]
        let output = ($start..$end).into_par_iter();

        #[cfg(not(feature = "std"))]
        let output = ($start..$end);

        output
    }};
}