// SPDX-License-Identifier: AGPL-3.0-or-later
// There is NO WARRANTY.
+use syn::{parse_macro_input, Data, DataStruct, DeriveInput};
+use quote::{quote, quote_spanned};
+
+use itertools::Itertools;
+
+#[proc_macro_derive(ResolveConfig)]
+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,
+ _ => panic!(),
+ };
+
+ let target = &input.ident;
+ let names = fields.named.iter().map(
+ |f| f.ident.as_ref().unwrap()
+ )
+ .collect_vec();
+
+ let output = quote! {
+ impl #target {
+ const FIELDS: &[&str] = &[ #( #names ),* ];
+ }
+ };
+ output.into()
+}