|
13 | 13 | /// This is a version of the [`azip`] macro that requires the crate feature |
14 | 14 | /// `rayon` to be enabled. |
15 | 15 | /// |
| 16 | +/// See the [`azip`] macro for more details about the macro syntax! |
| 17 | +/// |
16 | 18 | /// This example: |
17 | 19 | /// |
18 | 20 | /// ```rust,ignore |
19 | | -/// par_azip!(mut a, b, c in { *a = b + c }) |
| 21 | +/// par_azip!((a in &mut a, &b in &b, &c in &c) { *a = b + c }) |
20 | 22 | /// ``` |
21 | 23 | /// |
22 | 24 | /// Is equivalent to: |
|
47 | 49 | /// // Compute a simple ternary operation: |
48 | 50 | /// // elementwise addition of b and c, stored in a |
49 | 51 | /// |
50 | | -/// par_azip!(mut a, b, c in { *a = b + c }); |
| 52 | +/// par_azip!((a in &mut a, &b in &b, &c in &c) *a = b + c); |
51 | 53 | /// |
52 | 54 | /// assert_eq!(a, &b + &c); |
53 | 55 | /// } |
54 | 56 | /// ``` |
55 | 57 | macro_rules! par_azip { |
56 | | - // Build Zip Rule (index) |
57 | | - (@parse [index => $a:expr, $($aa:expr,)*] $t1:tt in $t2:tt) => { |
58 | | - $crate::par_azip!(@finish ($crate::Zip::indexed($a)) [$($aa,)*] $t1 in $t2) |
59 | | - }; |
60 | | - // Build Zip Rule (no index) |
61 | | - (@parse [$a:expr, $($aa:expr,)*] $t1:tt in $t2:tt) => { |
62 | | - $crate::par_azip!(@finish ($crate::Zip::from($a)) [$($aa,)*] $t1 in $t2) |
63 | | - }; |
64 | | - // Build Finish Rule (both) |
65 | | - (@finish ($z:expr) [$($aa:expr,)*] [$($p:pat,)+] in { $($t:tt)*}) => { |
66 | | - use $crate::parallel::prelude::*; |
67 | | - #[allow(unused_mut)] |
68 | | - ($z) |
69 | | - $( |
70 | | - .and($aa) |
71 | | - )* |
72 | | - .par_apply(|$($p),+| { |
73 | | - $($t)* |
74 | | - }) |
75 | | - }; |
76 | | - // parsing stack: [expressions] [patterns] (one per operand) |
77 | | - // index uses empty [] -- must be first |
78 | | - (@parse [] [] index $i:pat, $($t:tt)*) => { |
79 | | - $crate::par_azip!(@parse [index =>] [$i,] $($t)*); |
80 | | - }; |
81 | | - (@parse [$($exprs:tt)*] [$($pats:tt)*] mut $x:ident ($e:expr) $($t:tt)*) => { |
82 | | - $crate::par_azip!(@parse [$($exprs)* $e,] [$($pats)* mut $x,] $($t)*); |
83 | | - }; |
84 | | - (@parse [$($exprs:tt)*] [$($pats:tt)*] mut $x:ident $($t:tt)*) => { |
85 | | - $crate::par_azip!(@parse [$($exprs)* &mut $x,] [$($pats)* mut $x,] $($t)*); |
86 | | - }; |
87 | | - (@parse [$($exprs:tt)*] [$($pats:tt)*] , $($t:tt)*) => { |
88 | | - $crate::par_azip!(@parse [$($exprs)*] [$($pats)*] $($t)*); |
89 | | - }; |
90 | | - (@parse [$($exprs:tt)*] [$($pats:tt)*] ref $x:ident ($e:expr) $($t:tt)*) => { |
91 | | - $crate::par_azip!(@parse [$($exprs)* $e,] [$($pats)* $x,] $($t)*); |
92 | | - }; |
93 | | - (@parse [$($exprs:tt)*] [$($pats:tt)*] ref $x:ident $($t:tt)*) => { |
94 | | - $crate::par_azip!(@parse [$($exprs)* &$x,] [$($pats)* $x,] $($t)*); |
95 | | - }; |
96 | | - (@parse [$($exprs:tt)*] [$($pats:tt)*] $x:ident ($e:expr) $($t:tt)*) => { |
97 | | - $crate::par_azip!(@parse [$($exprs)* $e,] [$($pats)* &$x,] $($t)*); |
98 | | - }; |
99 | | - (@parse [$($exprs:tt)*] [$($pats:tt)*] $x:ident $($t:tt)*) => { |
100 | | - $crate::par_azip!(@parse [$($exprs)* &$x,] [$($pats)* &$x,] $($t)*); |
101 | | - }; |
102 | | - (@parse [$($exprs:tt)*] [$($pats:tt)*] $($t:tt)*) => { }; |
103 | 58 | ($($t:tt)*) => { |
104 | | - $crate::par_azip!(@parse [] [] $($t)*); |
105 | | - } |
| 59 | + $crate::azip!(@build par_apply $($t)*) |
| 60 | + }; |
106 | 61 | } |
0 commit comments