From: Ian Jackson Date: Sat, 24 Jul 2021 01:03:15 +0000 (+0100) Subject: macros wip X-Git-Tag: hippotat/1.0.0~499 X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~ian/git?a=commitdiff_plain;h=ba839a356e2f45b012045d2854d80d5522c6af47;p=hippotat.git macros wip Signed-off-by: Ian Jackson --- diff --git a/macros/macros.rs b/macros/macros.rs index 6576c27..7ef226b 100644 --- a/macros/macros.rs +++ b/macros/macros.rs @@ -4,6 +4,7 @@ use syn::{parse_macro_input, Data, DataStruct, DeriveInput}; use quote::{quote, quote_spanned}; +use proc_macro2::Literal; use itertools::Itertools; @@ -18,13 +19,13 @@ pub fn resolve(input: proc_macro::TokenStream) -> proc_macro::TokenStream { let target = &input.ident; let names = fields.named.iter().map( - |f| f.ident.as_ref().unwrap() + |f| Literal::string( &f.ident.as_ref().unwrap().to_string() ) ) .collect_vec(); let output = quote! { impl #target { - const FIELDS: &[&str] = &[ #( #names ),* ]; + const FIELDS: &'static [&'static str] = &[ #( #names ),* ]; } }; output.into() diff --git a/src/config.rs b/src/config.rs index 7f90f4b..8fb526d 100644 --- a/src/config.rs +++ b/src/config.rs @@ -23,6 +23,7 @@ pub struct Opts { pub struct CidrString(pub String); +#[derive(hippotat_macros::ResolveConfig)] pub struct InstanceConfig { /* // Exceptional settings @@ -147,6 +148,8 @@ impl Aggregate { let loc = Arc::new(path.to_owned()); for (sn, vars) in map { + dbg!( InstanceConfig::FIELDS ); + let sn = sn.parse().dcontext(&sn)?; self.sections.entry(sn) .or_default()