|
103 | 103 | macro_rules! azip {
|
104 | 104 | // Indexed with a single producer
|
105 | 105 | // we allow an optional trailing comma after the producers in each rule.
|
106 |
| - ((index $index:pat, $first_pat:pat in $first_prod:expr $(,)?) $body:expr) => { |
107 |
| - $crate::Zip::indexed($first_prod).apply(|$index, $first_pat| $body) |
| 106 | + (@build $apply:ident (index $index:pat, $first_pat:pat in $first_prod:expr $(,)?) $body:expr) => { |
| 107 | + $crate::Zip::indexed($first_prod).$apply(|$index, $first_pat| $body) |
108 | 108 | };
|
109 | 109 | // Indexed with more than one producer
|
110 |
| - ((index $index:pat, $first_pat:pat in $first_prod:expr, $($pat:pat in $prod:expr),* $(,)?) $body:expr) => { |
| 110 | + (@build $apply:ident (index $index:pat, $first_pat:pat in $first_prod:expr, $($pat:pat in $prod:expr),* $(,)?) $body:expr) => { |
111 | 111 | $crate::Zip::indexed($first_prod)
|
112 | 112 | $(.and($prod))*
|
113 |
| - .apply(|$index, $first_pat, $($pat),*| $body) |
| 113 | + .$apply(|$index, $first_pat, $($pat),*| $body) |
114 | 114 | };
|
115 | 115 | // Unindexed with a single producer
|
116 |
| - (($first_pat:pat in $first_prod:expr $(,)?) $body:expr) => { |
117 |
| - $crate::Zip::from($first_prod).apply(|$first_pat| $body) |
| 116 | + (@build $apply:ident ($first_pat:pat in $first_prod:expr $(,)?) $body:expr) => { |
| 117 | + $crate::Zip::from($first_prod).$apply(|$first_pat| $body) |
118 | 118 | };
|
119 | 119 | // Unindexed with more than one producer
|
120 |
| - (($first_pat:pat in $first_prod:expr, $($pat:pat in $prod:expr),* $(,)?) $body:expr) => { |
| 120 | + (@build $apply:ident ($first_pat:pat in $first_prod:expr, $($pat:pat in $prod:expr),* $(,)?) $body:expr) => { |
121 | 121 | $crate::Zip::from($first_prod)
|
122 | 122 | $(.and($prod))*
|
123 |
| - .apply(|$first_pat, $($pat),*| $body) |
| 123 | + .$apply(|$first_pat, $($pat),*| $body) |
| 124 | + }; |
| 125 | + // catch-all rule |
| 126 | + (@build $($t:tt)*) => { compile_error!("Invalid syntax in azip!()") }; |
| 127 | + ($($t:tt)*) => { |
| 128 | + $crate::azip!(@build apply $($t)*) |
124 | 129 | };
|
125 | 130 | }
|
0 commit comments