zino_derive/
lib.rs

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
#![doc = include_str!("../README.md")]
#![doc(html_favicon_url = "https://zino.cc/assets/zino-logo.png")]
#![doc(html_logo_url = "https://zino.cc/assets/zino-logo.svg")]
#![forbid(unsafe_code)]

use proc_macro::TokenStream;
use syn::{parse_macro_input, DeriveInput};

mod decode_row;
mod entity;
mod model;
mod model_accessor;
mod model_hooks;
mod parser;
mod schema;

#[doc = include_str!("../docs/entity.md")]
#[proc_macro_derive(Entity, attributes(schema))]
pub fn derive_entity(item: TokenStream) -> TokenStream {
    let input = parse_macro_input!(item as DeriveInput);
    let output = entity::parse_token_stream(input);
    TokenStream::from(output)
}

#[doc = include_str!("../docs/schema.md")]
#[proc_macro_derive(Schema, attributes(schema))]
pub fn derive_schema(item: TokenStream) -> TokenStream {
    let input = parse_macro_input!(item as DeriveInput);
    let output = schema::parse_token_stream(input);
    TokenStream::from(output)
}

#[doc = include_str!("../docs/model_accessor.md")]
#[proc_macro_derive(ModelAccessor, attributes(schema))]
pub fn derive_model_accessor(item: TokenStream) -> TokenStream {
    let input = parse_macro_input!(item as DeriveInput);
    let output = model_accessor::parse_token_stream(input);
    TokenStream::from(output)
}

#[doc = include_str!("../docs/decode_row.md")]
#[proc_macro_derive(DecodeRow, attributes(schema))]
pub fn derive_decode_row(item: TokenStream) -> TokenStream {
    let input = parse_macro_input!(item as DeriveInput);
    let output = decode_row::parse_token_stream(input);
    TokenStream::from(output)
}

#[doc = include_str!("../docs/model_hooks.md")]
#[proc_macro_derive(ModelHooks, attributes(schema))]
pub fn derive_model_hooks(item: TokenStream) -> TokenStream {
    let input = parse_macro_input!(item as DeriveInput);
    let output = model_hooks::parse_token_stream(input);
    TokenStream::from(output)
}

#[doc = include_str!("../docs/model.md")]
#[proc_macro_derive(Model, attributes(schema))]
pub fn derive_model(item: TokenStream) -> TokenStream {
    let input = parse_macro_input!(item as DeriveInput);
    let output = model::parse_token_stream(input);
    TokenStream::from(output)
}