syn icon indicating copy to clipboard operation
syn copied to clipboard

improve docs for writing attribute procedural macros that parse ItemFn

Open zachreizner opened this issue 5 years ago • 1 comments

The signature of these procedural macros is fn cool_fn_macro(attr: TokenStream, item: TokenStream) -> TokenStream and they usually start with let mut function = parse_macro_input!(item as ItemFn);. The attr argument that the macro receives includes only the inner part of the attribute:

#[cool_fn_macro(category = "suite", name = "task_long")]
                ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
                            attr: TokenStream

The way to parse this attr is with parse_macro_input!(attr as Vec<NestedMeta>) or equivalently parse_macro_input!(attr as AttributeArgs). But this was hard to discover on my part.

I suggest including this last bit of information in the AttributeArgs, Meta, and any related pages so that future authors will have an easier time than I did. In particular, it would be nice to find the correct type in the doc index by searching for similar syntax, similarly to how the short docs for the other types is written out.

zachreizner avatar Apr 03 '19 23:04 zachreizner

Seems like this is not valid for v2.

ultimaweapon avatar Sep 03 '23 02:09 ultimaweapon