aboutsummaryrefslogtreecommitdiffstats
path: root/plugin_derive/src/lib.rs
diff options
context:
space:
mode:
authorJokler <jokler.contact@gmail.com>2017-10-10 17:48:30 +0200
committerJokler <jokler.contact@gmail.com>2017-10-11 15:41:32 +0200
commit0195219d5c0b0ff1486b3e6bdcd62a807d3d2932 (patch)
tree0e518f025de563a9df792ad8237275d3ad71af5d /plugin_derive/src/lib.rs
parentec33c870852f8a52f3cc0cf5a84b99c775dee1e3 (diff)
downloadfrippy-0195219d5c0b0ff1486b3e6bdcd62a807d3d2932.tar.gz
frippy-0195219d5c0b0ff1486b3e6bdcd62a807d3d2932.zip
Create plugin_derive to replace the register_plugin macro
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)
+ }
+ }
+ }
+}