let mut output = vec![];
let mut global_fields = vec![];
let mut global_assignments = vec![];
- let mut inspects = vec![];
+ let mut g_inspects = vec![];
for field in &fields.named {
//dbg!(field);
let fname = &field.ident.as_ref().unwrap();
for attr in &field.attrs {
let atspan = attr.path.segments.last().unwrap().ident.span();
if attr.tokens.is_empty() {
+ let inspect = quote!{
+ #fname_lit => &self.#fname,
+ };
if attr.path == parse_quote!{ per_client } {
set_skl(quote_spanned!{fname_span=> SectionKindList::PerClient });
continue;
#fname: <#ty as ResolveGlobal>::resolve
(l.iter().map(|e| &e.#fname)),
));
- inspects.push(quote!{
- #fname_lit => &self.#fname,
- });
+ g_inspects.push(inspect);
continue;
}
method = attr.path.to_token_stream();
let global = syn::Ident::new(&format!("{}Global", top_ident),
top_ident.span());
+ let mk_inspects = |inspects: Vec<_>| quote! {
+ pub fn inspect_key(&self, field: &'_ str)
+ -> Option<&dyn InspectableConfigValue> {
+ Some(match field {
+ #( #inspects )*
+ _ => return None,
+ })
+ }
+ };
+ let g_inspects = mk_inspects(g_inspects);
+
let output = quote! {
impl #target {
const FIELDS: &'static [(&'static str, SectionKindList)]
#( #global_assignments )*
} }
- pub fn inspect_key(&self, field: &'_ str)
- -> Option<&dyn InspectableConfigValue> {
- Some(match field {
- #( #inspects )*
- _ => return None,
- })
- }
+ #g_inspects
}
};