Skip to content

Commit f7645e8

Browse files
committed
FIX: Refactor zipmacro to use internal rules
This makes the apply method a parameter (so that par_azip can reuse azip, in the next commit).
1 parent b03446d commit f7645e8

File tree

1 file changed

+13
-8
lines changed

1 file changed

+13
-8
lines changed

src/zip/zipmacro.rs

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -103,23 +103,28 @@
103103
macro_rules! azip {
104104
// Indexed with a single producer
105105
// 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)
108108
};
109109
// 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) => {
111111
$crate::Zip::indexed($first_prod)
112112
$(.and($prod))*
113-
.apply(|$index, $first_pat, $($pat),*| $body)
113+
.$apply(|$index, $first_pat, $($pat),*| $body)
114114
};
115115
// 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)
118118
};
119119
// 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) => {
121121
$crate::Zip::from($first_prod)
122122
$(.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)*)
124129
};
125130
}

0 commit comments

Comments
 (0)