syn icon indicating copy to clipboard operation
syn copied to clipboard

Some documentation on how to access attributes from derive macros

Open tgross35 opened this issue 2 years ago • 0 comments

Hello Syn team,

I was trying to create a macro to be used with this sort of syntax:

#[derive(MyThing)]
#[mything(key = "MYKEY", newattr="SOMETHING")]
struct XXX;

And access key and newattr in the macro definition, which uses:

#[proc_macro_derive(AffixToken, attributes(key, newattr))]

But didn't see anything like that in the docs. It looks like the entire key = "MYKEY", newattr="SOMETHING" is stored here:

input.attrs.get(0).unwrap().tokens.get(0).unwrap().stream // iterate this

And is split across idents, punctuation, and literals. I'm just unsure whether this is the "correct" way to access them, and figured others would benefit from this being in the docs as well.

Thanks!

tgross35 avatar Jun 19 '22 19:06 tgross35