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
extern crate proc_macro;
extern crate proc_macro2;
#[macro_use] extern crate quote;
extern crate syn;
mod common;
mod style;
mod utils;
use proc_macro::TokenStream;
#[proc_macro_derive(WidgetCommon, attributes(conrod, common_builder))]
pub fn widget_common(input: TokenStream) -> TokenStream {
impl_derive(input, common::impl_widget_common)
}
#[proc_macro_derive(WidgetCommon_, attributes(conrod, common_builder))]
pub fn widget_common_(input: TokenStream) -> TokenStream {
impl_derive(input, common::impl_widget_common_)
}
#[proc_macro_derive(WidgetStyle, attributes(conrod, default))]
pub fn widget_style(input: TokenStream) -> TokenStream {
impl_derive(input, style::impl_widget_style)
}
#[proc_macro_derive(WidgetStyle_, attributes(conrod, default))]
pub fn widget_style_(input: TokenStream) -> TokenStream {
impl_derive(input, style::impl_widget_style_)
}
fn impl_derive(
input: TokenStream,
generate_derive: fn(&syn::DeriveInput) -> proc_macro2::TokenStream,
) -> TokenStream
{
let ast = syn::parse(input).unwrap();
let gen = generate_derive(&ast);
gen.into()
}