From 311b49a2fdd97b8b870dbaccccb55058ee0207c8 Mon Sep 17 00:00:00 2001 From: Melody Horn / boringcactus Date: Sun, 13 Jun 2021 16:33:46 -0600 Subject: lay groundwork for models --- tosin-macros/src/lib.rs | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 tosin-macros/src/lib.rs (limited to 'tosin-macros/src/lib.rs') diff --git a/tosin-macros/src/lib.rs b/tosin-macros/src/lib.rs new file mode 100644 index 0000000..c0651fa --- /dev/null +++ b/tosin-macros/src/lib.rs @@ -0,0 +1,26 @@ +extern crate proc_macro; + +use proc_macro::TokenStream; +use quote::quote; + +#[proc_macro_derive(Model, attributes(model))] +pub fn model_derive(input: TokenStream) -> TokenStream { + // Construct a representation of Rust code as a syntax tree + // that we can manipulate + let ast = syn::parse(input).unwrap(); + + // Build the trait implementation + impl_model(&ast) +} + +fn impl_model(ast: &syn::DeriveInput) -> TokenStream { + let name = &ast.ident; + let gen = quote! { + impl #name { + fn hello_macro() { + println!("Hello, Macro! My name is {}!", stringify!(#name)); + } + } + }; + gen.into() +} -- cgit v1.2.3