I was wondering how I could have a macro generating a struct with fields names created partly from the macro's params :
#[macro_export]
macro_rules! my_macro {
($($comp:ident),+) => {
{
struct MyStruct {
$(
field1_$comp: $comp,
field2_$comp: usize,
)+
}
MyStruct {
$(
field1_$comp: $comp::default(),
field2_$comp: 0,
)+
}
}
};
}
This doesn't work, with the error "expected : or ;". Is there a way to generate field names with the params ?
I would like something like :
my_macro!(f32, f64);
would expand to :
MyStruct {
field1_f32: f32,
field2_f32: usize,
field1_f64: f64,
field2_f64: usize
}