Skip to content

Instantly share code, notes, and snippets.

@substack substack/main.rs
Created Jan 11, 2019

Embed
What would you like to do?
rust combination macro
macro_rules! comb {
($f:tt, ($($x:tt),*), $H:expr, $($T:expr),*) => {
comb!($f, ($($x,)*$H), $($T),*);
comb!($f, ($($x,)*($H,$H)), $($T),*);
};
($f:tt, ($($x:tt),*), $H:expr) => {
$f!("{:?}", ($($x),*,$H));
$f!("{:?}", ($($x),*,($H,$H)));
};
}
fn main() -> () {
comb!(println, (), "A", "B", "C");
}
("A", "B", "C")
("A", "B", ("C", "C"))
("A", ("B", "B"), "C")
("A", ("B", "B"), ("C", "C"))
(("A", "A"), "B", "C")
(("A", "A"), "B", ("C", "C"))
(("A", "A"), ("B", "B"), "C")
(("A", "A"), ("B", "B"), ("C", "C"))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.