Skip to content

Commit

Permalink
Macro hygiene: qualified paths only
Browse files Browse the repository at this point in the history
Is conflict with `.map` and `.zip` absolutely impossible?
  • Loading branch information
Philippe-Cholet committed May 21, 2024
1 parent 26e35d0 commit 2ca3c5a
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,10 @@ macro_rules! iproduct {
$crate::__std_iter::once(())
);
($I:expr $(,)?) => (
$crate::__std_iter::IntoIterator::into_iter($I).map(|elt| (elt,))
$crate::__std_iter::Iterator::map(
$crate::__std_iter::IntoIterator::into_iter($I),
|elt| (elt,)
)
);
($I:expr, $J:expr $(,)?) => (
$crate::Itertools::cartesian_product(
Expand Down Expand Up @@ -330,19 +333,24 @@ macro_rules! izip {

// binary
($first:expr, $second:expr $(,)*) => {
$crate::izip!($first)
.zip($second)
$crate::__std_iter::Iterator::zip(
$crate::__std_iter::IntoIterator::into_iter($first),
$second,
)
};

// n-ary where n > 2
( $first:expr $( , $rest:expr )* $(,)* ) => {
$crate::izip!($first)
{
let iter = $crate::__std_iter::IntoIterator::into_iter($first);
$(
.zip($rest)
let iter = $crate::__std_iter::Iterator::zip(iter, $rest);
)*
.map(
$crate::__std_iter::Iterator::map(
iter,
$crate::izip!(@closure a => (a) $( , $rest )*)
)
}
};
}

Expand Down

0 comments on commit 2ca3c5a

Please sign in to comment.