1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21
extern crate proc_macro; #[macro_use] extern crate quote; extern crate syn; use proc_macro::TokenStream; use syn::DeriveInput; #[proc_macro_derive(Storable)] pub fn storable(input: TokenStream) -> TokenStream { let ast: DeriveInput = syn::parse(input).expect("Couldn't parse item"); impl_storable(&ast).into() } fn impl_storable(ast: &DeriveInput) -> quote::Tokens { let name = &ast.ident; quote! { impl Storable for #name {} } }