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
extern crate proc_macro;
extern crate syn;
#[macro_use]
extern crate quote;

use proc_macro::TokenStream;

#[proc_macro_derive(ResxPath)]
pub fn resx_path(input: TokenStream) -> TokenStream {
    let s = input.to_string();
    let ast = syn::parse_derive_input(&s).unwrap();
    let gen = impl_resx_path(&ast);
    gen.parse().unwrap()
}

fn impl_resx_path(ast: &syn::DeriveInput) -> quote::Tokens {
    let name = &ast.ident;
    quote! {
        impl ResxPath for #name {
            fn path(self) -> String {
                self.0
            }
            fn new(path: String) -> Self {
                #name(path)
            }
        }
    }
}

#[proc_macro_derive(ResxRB)]
pub fn resx_rb(input: TokenStream) -> TokenStream {
    let s = input.to_string();
    let ast = syn::parse_derive_input(&s).unwrap();
    let gen = impl_resx_rb(&ast);
    gen.parse().unwrap()
}

fn impl_resx_rb(ast: &syn::DeriveInput) -> quote::Tokens {
    let name = &ast.ident;
    quote! {
        impl ResxRB for #name {}
    }
}


#[proc_macro_derive(ResxInstanceRB)]
pub fn resx_instance_rb(input: TokenStream) -> TokenStream {
    let s = input.to_string();
    let ast = syn::parse_derive_input(&s).unwrap();
    let gen = impl_resx_instance_rb(&ast);
    gen.parse().unwrap()
}

fn impl_resx_instance_rb(ast: &syn::DeriveInput) -> quote::Tokens {
    let name = &ast.ident;
    quote! {
        impl ResxInstanceRB for #name {}
    }
}