0
macro_rules! log {
    ($($x:expr),*) => {
        {
            $(
             //how to detect $x in the Macro repetition?

            )*
        }
    };
}

I don't want to use ($($x:ident),*). The log! macro can log the expression and then I want to match the variable type.

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
CS QGB
  • 297
  • 1
  • 3
  • 12
  • 2
    Hi there. It's currently really hard for us to understand what exactly you are asking. What is your goal exactly? Please [edit] your question to clarify that. – Lukas Kalbertodt Nov 14 '19 at 23:00

1 Answers1

3

Macros only can access token streams, and cannot say anything more about those tokens, apart from what is explicitly given to the macro.

For example, consider this code:

fn main() {
    let mut foo: i32 = 1;
    my_macro!(foo);
}

The only information available to the macro my_macro is the input token foo. It can match that foo is is an identifier but it can't say anything more about it. The fact that there is mutable binding called foo, or that this binding is an i32 are just not available inside the macro.

Peter Hall
  • 53,120
  • 14
  • 139
  • 204