From d88444cd26e29a4cc391d21949a5e22dec25e5c1 Mon Sep 17 00:00:00 2001 From: Ian Jackson Date: Sat, 7 Aug 2021 22:25:06 +0100 Subject: [PATCH] config macros: wip global Signed-off-by: Ian Jackson --- macros/macros.rs | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) diff --git a/macros/macros.rs b/macros/macros.rs index 43efcf6..345c756 100644 --- a/macros/macros.rs +++ b/macros/macros.rs @@ -45,6 +45,9 @@ use itertools::Itertools; /// } /// } /// } +/// +/// pub struct InstanceConfigCommon { +/// { /// ``` #[proc_macro_derive(ResolveConfig, attributes( limited, server, client, computed, special, @@ -53,10 +56,18 @@ use itertools::Itertools; pub fn resolve(input: proc_macro::TokenStream) -> proc_macro::TokenStream { let input = parse_macro_input!(input as DeriveInput); - let fields = match input.data { - Data::Struct(DataStruct { fields: syn::Fields::Named(ref f),.. }) => f, + let (fields, top_ident) = match input { + DeriveInput { + ref ident, + data: Data::Struct(DataStruct { + fields: syn::Fields::Named(ref f), + .. + }), + .. + } => (f, ident), _ => panic!(), }; +dbg!(&top_ident); let target = &input.ident; @@ -124,6 +135,9 @@ pub fn resolve(input: proc_macro::TokenStream) -> proc_macro::TokenStream { } //dbg!(&output); + let global = syn::Ident::new(&format!("{}Common", top_ident), + top_ident.span()); + let output = quote! { impl #target { const FIELDS: &'static [(&'static str, SectionKindList)] @@ -137,7 +151,11 @@ pub fn resolve(input: proc_macro::TokenStream) -> proc_macro::TokenStream { }) } } + + pub struct #global { + } }; + //eprintln!("{}", &output); output.into() } -- 2.30.2