} => (f, ident),
_ => panic!(),
};
-dbg!(&top_ident);
let target = &input.ident;
let mut names = vec![];
let mut output = vec![];
let mut global_fields = vec![];
+ let mut global_assignments = vec![];
for field in &fields.named {
//dbg!(field);
let fname = &field.ident.as_ref().unwrap();
+ let ty = &field.ty;
let fname_span = fname.span();
let skl = RefCell::new(None);
let set_skl = |new| {
attrs: vec![],
..field.clone()
});
+ global_assignments.push(quote_spanned!(fname_span=>
+ #fname: <#ty as ResolveGlobal>::resolve
+ (l.iter().map(|e| &e.#fname)),
+ ));
continue;
}
method = attr.path.to_token_stream();
}
//dbg!(&output);
- let global = syn::Ident::new(&format!("{}Common", top_ident),
+ let global = syn::Ident::new(&format!("{}Global", top_ident),
top_ident.span());
let output = quote! {
pub struct #global {
#( #global_fields ),*
}
+
+ impl #global {
+ pub fn from(l: &[#top_ident]) -> #global { #global {
+ #( #global_assignments )*
+ } }
+ }
};
//eprintln!("{}", &output);
}
}
+trait ResolveGlobal<'i> where Self: 'i {
+ fn resolve<I>(it: I) -> Self
+ where I: Iterator<Item=&'i Self>;
+}
+impl<'i,T> ResolveGlobal<'i> for T where T: Eq + Clone + Debug + 'i {
+ fn resolve<I>(mut it: I) -> Self
+ where I: Iterator<Item=&'i Self>
+ {
+ let first = it.next().expect("empty instances no global!");
+ for x in it { assert_eq!(x, first); }
+ first.clone()
+ }
+}
+
#[throws(AE)]
pub fn read(opts: &Opts, end: LinkEnd) -> Vec<InstanceConfig> {
let agg = (||{