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 mk_inspects = |self_, inspects: Vec<_>| quote! {
+ impl InspectableConfig for #self_ {
+ fn inspect_key(&self, field: &'_ str)
+ -> Option<&dyn InspectableConfigValue> {
+ Some(match field {
+ #( #inspects )*
+ _ => return None,
+ })
+ }
}
};
- let g_inspects = mk_inspects(g_inspects);
+ let g_inspects = mk_inspects(&global, g_inspects);
let output = quote! {
impl #target {
pub fn from(l: &[#top_ident]) -> #global { #global {
#( #global_assignments )*
} }
-
- #g_inspects
}
+
+ #g_inspects
};
//eprintln!("{}", &output);
pub extra_config: Vec<PathBuf>,
}
+pub trait InspectableConfig {
+ fn inspect_key(&self, field: &'_ str)
+ -> Option<&dyn InspectableConfigValue>;
+}
+
pub trait InspectableConfigValue {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result;
}
pub use eyre::WrapErr;
pub use eyre::Error as AE;
-pub use crate::config::{self, InspectableConfigValue, InstanceConfig};
+pub use crate::config::{self, InstanceConfig};
+pub use crate::config::{InspectableConfig, InspectableConfigValue};
pub use crate::config::{DisplayInspectable, U32Ext as _};
pub use crate::impl_inspectable_config_value;
pub use crate::ini;