0

I need to check whether the identifier begins with an underscore. This does not work:

#[macro_export]
macro_rules! UNDECORED {
    (_$_i:ident) => {... do something if underscored};
    ($_i:ident) => {... do something else};
}

Where is the mistake?

Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
Aleksandr
  • 3
  • 1

1 Answers1

2

Macros receive "tokens" as input; the leading underscore is not a separate token, and you cannot match partial tokens.

You could stringify! the identifier and match the name at runtime.

Stefan
  • 5,304
  • 2
  • 25
  • 44