I am learning syn and was wondering if I am able to look up struct syntax based only on the struct identifier as syntax input to a procedural macro without using a derive or attribute proc macro.
For example:
struct Ab {
a: f32,
b: u32 }
my_macro!(Ab)
Should look up if the struct Ab exists in the file and then turn the syntax into a TokenStream.
You want reflection, in other words. Nope, not gonna happen. Not anytime soon. Macros work with tokens, nothing else exist at this stage of the compilation process.
No, this is not possible. Macros run interleaved with name resolution and parsing of items (such as structs), and before processing the items’ tokens into actual definitions, so the information you are looking for does not even reliably exist yet.