mirror of
https://github.com/Start9Labs/patch-db.git
synced 2026-03-26 02:11:54 +00:00
wip: macros
This commit is contained in:
17
patch-db-macro/Cargo.toml
Normal file
17
patch-db-macro/Cargo.toml
Normal 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
13
patch-db-macro/src/lib.rs
Normal 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()
|
||||
}
|
||||
Reference in New Issue
Block a user