wip: macros

This commit is contained in:
Aiden McClelland
2021-03-23 18:10:22 -06:00
parent 4e96c64c1b
commit 2c3fd8159e
9 changed files with 148 additions and 68 deletions

17
patch-db-macro/Cargo.toml Normal file
View File

@@ -0,0 +1,17 @@
[package]
name = "patch-db-macro"
version = "0.1.0"
authors = ["Aiden McClelland <me@drbonez.dev>"]
edition = "2018"
description = "macros for defining typed patch dbs"
license = "MIT"
repository = "https://github.com/Start9Labs/patch-db"
[lib]
proc-macro = true
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]
patch-db-macro-internals = { path = "../patch-db-macro-internals" }
syn = "1.0.62"
proc-macro2 = "1.0.1"

13
patch-db-macro/src/lib.rs Normal file
View File

@@ -0,0 +1,13 @@
extern crate proc_macro;
use proc_macro::TokenStream;
use syn::{parse_macro_input, AttributeArgs, Item};
#[proc_macro_attribute]
pub fn model(attr_in: TokenStream, item_in: TokenStream) -> TokenStream {
let mut res = proc_macro2::TokenStream::from(item_in.clone());
let attr = parse_macro_input!(attr_in as AttributeArgs);
let item = parse_macro_input!(item_in as Item);
res.extend(patch_db_macro_internals::build_model(&attr, &item));
res.into()
}