]>
git.proxmox.com Git - rustc.git/blob - src/doc/book/listings/ch19-advanced-features/no-listing-21-pancakes/hello_macro/hello_macro_derive/src/lib.rs
1 use proc_macro
::TokenStream
;
5 #[proc_macro_derive(HelloMacro)]
6 pub fn hello_macro_derive(input
: TokenStream
) -> TokenStream
{
7 // Construct a representation of Rust code as a syntax tree
8 // that we can manipulate
9 let ast
= syn
::parse(input
).unwrap();
11 // Build the trait implementation
12 impl_hello_macro(&ast
)
15 fn impl_hello_macro(ast
: &syn
::DeriveInput
) -> TokenStream
{
16 let name
= &ast
.ident
;
18 impl HelloMacro
for #name {
20 println
!("Hello, Macro! My name is {}!", stringify
!(#name));