Macro parse_macro_input
macro_rules! parse_macro_input {
($tokenstream:ident as $ty:ty) => { ... };
($tokenstream:ident with $parser:path) => { ... };
($tokenstream:ident) => { ... };
}
Parse the input TokenStream of a macro, triggering a compile error if the tokens fail to parse.
Refer to the parse module documentation for more details about parsing
in Syn.
Intended usage
This macro must be called from a function that returns
proc_macro::TokenStream. Usually this will be your proc macro entry point,
the function that has the #[proc_macro] / #[proc_macro_derive] /
#[proc_macro_attribute] attribute.
# extern crate proc_macro;
#
use TokenStream;
use ;
use ;
# const IGNORE: &str = stringify! ;
Usage with Parser
This macro can also be used with the Parser trait for types that have
multiple ways that they can be parsed.
# extern crate proc_macro;
#
# use TokenStream;
# use ;
# use ParseStream;
#
#
#
# const IGNORE: &str = stringify! ;
Expansion
parse_macro_input!($variable as $Type) expands to something like:
# extern crate proc_macro;
#
# macro_rules! doc_test {
# ($variable:ident as $Type:ty) => {
match syn::parse::<$Type>($variable) {
Ok(syntax_tree) => syntax_tree,
Err(err) => return proc_macro::TokenStream::from(err.to_compile_error()),
}
# };
# }
#
# fn test(input: proc_macro::TokenStream) -> proc_macro::TokenStream {
# let _ = doc_test!(input as syn::Ident);
# proc_macro::TokenStream::new()
# }