Function parser
fn parser<impl FnMut(ParseNestedMeta) -> Result<()>: FnMut(ParseNestedMeta<'_>) -> crate::error::Result<()>>(logic: impl FnMut(ParseNestedMeta<'_>) -> crate::error::Result<()>) -> impl Parser<Output = ()>
Make a parser that is usable with parse_macro_input! in a
#[proc_macro_attribute] macro.
Warning: When parsing attribute args other than the
proc_macro::TokenStream input of a proc_macro_attribute, you do not
need this function. In several cases your callers will get worse error
messages if you use this function, because the surrounding delimiter's span
is concealed from attribute macros by rustc. Use
Attribute::parse_nested_meta instead.
Example
This example implements an attribute macro whose invocations look like this:
# const IGNORE: &str = stringify! ;
The "parameters" supported by the attribute are:
kind = "..."hotwith(sugar, milk, ...), a comma-separated list of ingredients
# extern crate proc_macro;
#
use TokenStream;
use ;
# const IGNORE: &str = stringify! ;
The syn::meta library will take care of dealing with the commas including
trailing commas, and producing sensible error messages on unexpected input.
error: expected `,`
--> src/main.rs:3:37
|
3 | #[tea(kind = "EarlGrey", with(sugar = "lol", milk))]
| ^
Example
Same as above but we factor out most of the logic into a separate function.
# extern crate proc_macro;
#
use TokenStream;
use ParseNestedMeta;
use ;
use ;
# const IGNORE: &str = stringify! ;