ux_macro/
lib.rs

1use proc_macro::TokenStream;
2use syn::{parse_macro_input, DeriveInput};
3
4use quote::quote;
5
6mod macros;
7use macros::getters::expand_getters;
8
9#[proc_macro_derive(Getters)]
10pub fn getters(input: TokenStream) -> TokenStream {
11    let input = parse_macro_input!(input as DeriveInput);
12    expand_getters(input)
13        .unwrap_or_else(syn::Error::into_compile_error)
14        .into()
15}
16
17#[proc_macro_derive(Setters)]
18pub fn setters(input: TokenStream) -> TokenStream {
19    let input = parse_macro_input!(input as DeriveInput);
20    expand_getters(input)
21        .unwrap_or_else(syn::Error::into_compile_error)
22        .into()
23}
24
25#[proc_macro_derive(Application)]
26pub fn writable_template_derive(input: TokenStream) -> TokenStream {
27    let input = parse_macro_input!(input as DeriveInput);
28
29    // get the name of the type we want to implement the trait for
30    let name = &input.ident;
31
32    let expanded = quote! {
33      impl #name {
34        fn run() -> #name {
35            application::init();
36            let app = Self::new();
37            application::run();
38            app
39        }
40
41        fn quit() {
42            application::quit()
43        }
44      }
45    };
46
47    TokenStream::from(expanded)
48}
49
50#[cfg(test)]
51mod tests {
52    #[test]
53    fn it_works() {
54        assert_eq!(2 + 2, 4);
55    }
56}