How to define a macro with an indefinite amount of arguments inside another macro?

Viewed 1607

This works, but test_macro accepts only one argument:

macro_rules! test_define (
    ($name:ident) => (
        macro_rules! $name (
            ( $x:expr ) => (
                // something
            )
        );
    )
);

test_define!(test_macro);

If I try and do this:

macro_rules! test_define2 (
    ($name:ident) => (
        macro_rules! $name (
            ( $($x:expr),* ) => (
                // something
            )
        );
    )
);

test_define2!(test_macro2);

Compilation fails with:

error: attempted to repeat an expression containing no syntax variables matched as repeating at this depth
 --> src/main.rs:4:16
  |
4 |             ( $($x:expr),* ) => (
  |                ^^^^^^^^^
2 Answers
Related