aboutsummaryrefslogtreecommitdiff
path: root/tosin-macros
diff options
context:
space:
mode:
authorMelody Horn / boringcactus <melody@boringcactus.com>2021-06-13 16:33:46 -0600
committerMelody Horn / boringcactus <melody@boringcactus.com>2021-06-13 16:33:46 -0600
commit311b49a2fdd97b8b870dbaccccb55058ee0207c8 (patch)
tree1ca431733526cac1c7c2f7f1bfda7324ae088d50 /tosin-macros
parentcc7d316e588c21de1023d6a76d4ea5e7b893977a (diff)
downloadtosin-311b49a2fdd97b8b870dbaccccb55058ee0207c8.tar.gz
tosin-311b49a2fdd97b8b870dbaccccb55058ee0207c8.zip
lay groundwork for models
Diffstat (limited to 'tosin-macros')
-rw-r--r--tosin-macros/Cargo.toml14
-rw-r--r--tosin-macros/src/lib.rs26
2 files changed, 40 insertions, 0 deletions
diff --git a/tosin-macros/Cargo.toml b/tosin-macros/Cargo.toml
new file mode 100644
index 0000000..4a58a20
--- /dev/null
+++ b/tosin-macros/Cargo.toml
@@ -0,0 +1,14 @@
+[package]
+name = "tosin-macros"
+version = "0.1.0"
+authors = ["Melody Horn / boringcactus <melody@boringcactus.com>"]
+edition = "2018"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[lib]
+proc-macro = true
+
+[dependencies]
+syn = "1.0"
+quote = "1.0"
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()
+}