Hi,
I have a rust macro which takes a type in as one of its parameters. I am trying to use &
before the typename as something of a flag, so that &MyType
gets treated slighly differently by the macro's internals (via a second, helper macro) than MyType
. The reason I decided to attempt that (at the risk of sounding XY) is that there doesn't seem to be any native way to support a "flag" with declarative macros, since repetitions must have a syntax variable in them in order to make use of any information about them (i.e., it is impossible to determine using $(&)?
whether the &
was actually present or not).
In this vein, I ran into an issue: the declarative macro engine seems to be incapable of separating the &
from the rest of the type. I have produced a minimial working example here. Note that the result of running the code is no
, even though the type passed into the macro does in fact begin with &
. This seems counterintuitive to me, since I expected the syntax to just be dumped into the input of the second macro.
I have a multi-part question:
- Is this the intended/specified behaviour of the declarative macro system?
- Is there any known workaround or other method of incorporating a "flag" of sorts into a macro?
Note that I cannot simply have two patterns for my macro (one with a flag and one without), since the location of the "flag" in my case is nested within repetitions.