diff options
Diffstat (limited to 'plugin_derive')
| -rw-r--r-- | plugin_derive/Cargo.toml | 11 | ||||
| -rw-r--r-- | plugin_derive/src/lib.rs | 27 |
2 files changed, 38 insertions, 0 deletions
diff --git a/plugin_derive/Cargo.toml b/plugin_derive/Cargo.toml new file mode 100644 index 0000000..0b62f9f --- /dev/null +++ b/plugin_derive/Cargo.toml @@ -0,0 +1,11 @@ +[package] +name = "plugin_derive" +version = "0.1.0" +authors = ["Jokler <jokler.contact@gmail.com>"] + +[lib] +proc-macro = true + +[dependencies] +syn = "0.11.11" +quote = "0.3.15" diff --git a/plugin_derive/src/lib.rs b/plugin_derive/src/lib.rs new file mode 100644 index 0000000..704d6ef --- /dev/null +++ b/plugin_derive/src/lib.rs @@ -0,0 +1,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) + } + } + } +} |
