aboutsummaryrefslogtreecommitdiffstats
path: root/plugin_derive/src/lib.rs
blob: 704d6ef9be236739e2b484c92fdbdc9c001464e6 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
//! Provides the plugin derive macro

extern crate proc_macro;
extern crate syn;
#[macro_use]
extern crate quote;

use proc_macro::TokenStream;

#[proc_macro_derive(PluginName)]
pub fn derive_plugin(data: TokenStream) -> TokenStream {
    let ast = syn::parse_derive_input(&data.to_string()).unwrap();
    let gen = expand_plugin(&ast);
    gen.parse().unwrap()
}

fn expand_plugin(ast: &syn::DeriveInput) -> quote::Tokens {
    let name = &ast.ident;
    quote! {
        impl PluginName for #name {
            fn name(&self) -> &str {
                stringify!(#name)
            }
        }
    }
}