Macro repetition with multiple rules

I think what you want can be achieved by splitting the macro into two macro: one to do the switch between the different kind of rules, and one to repeat multiple inputs.

Here is a minimal example showing what I mean:

fn main() {
    foo();
    bar();
    baz();
}

macro_rules! switch {
    ({ $name:ident, $doc:literal }) => {
        #[doc = $doc]
        fn $name() {}
    };
    ($name:ident) => {
        fn $name() {}
    };
}

macro_rules! repeat {
    ($($tokens:tt),*) => {
        $(
            switch!($tokens);
        )*
    }
}

repeat!(foo, {baz, "baz func"}, bar);
1 Like