chiark / gitweb /
config macros: wip global
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 7 Aug 2021 21:25:06 +0000 (22:25 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 7 Aug 2021 21:25:06 +0000 (22:25 +0100)
Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
macros/macros.rs

index 43efcf6cc5174c95a662d204f1a57a123799004a..345c756a07f633569028ec48a24e551e83e5c017 100644 (file)
@@ -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()
 }