summaryrefslogtreecommitdiffstats
path: root/plugin_derive/src/lib.rs
diff options
context:
space:
mode:
Diffstat (limited to 'plugin_derive/src/lib.rs')
-rw-r--r--plugin_derive/src/lib.rs27
1 files changed, 27 insertions, 0 deletions
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)
+ }
+ }
+ }
+}