1use proc_macro::TokenStream;
10
11use quote::quote;
12use syn::{self, DeriveInput};
13
14mod context;
15
16#[proc_macro_derive(Patchable, attributes(patchable))]
17pub fn derive_state_and_patchable_impl(input: TokenStream) -> TokenStream {
18 let input: DeriveInput = syn::parse_macro_input!(input as DeriveInput);
19 match context::MacroContext::new(&input) {
20 Ok(ctx) => {
21 let state_struct_def = ctx.build_state_struct();
22 let patchable_trait_impl = ctx.build_patchable_trait_impl();
23
24 quote! {
25 const _: () = {
26 #state_struct_def
27 #[automatically_derived]
28 #patchable_trait_impl
29 };
30 }
31 .into()
32 }
33 Err(e) => e.to_compile_error().into(),
34 }
35}