Hello,
I am fighting with a macro:
pub(crate) enum Args<A, B, C, D, E> {
Args0(A),
Args1(B),
Args2(C),
Args3(D),
Args4(E),
}
macro_rules! test {
($t:ty,$($value:expr),*) => {
#[test]
fn test() {
test_func(InputArgs {
args: {
let mut v: Vec<$t> = Vec::new();
$(
if v.len()==0 {
v.push(Args::Args0($value));
} else if v.len()==1 {
v.push( Args::Args1($value));
}else if v.len()==2 {
v.push( Args::Args2($value));
}else if v.len()==3 {
v.push( Args::Args3($value));
}else if v.len()==4 {
v.push( Args::Args4($value));
}
)*
v
},
});
run($($value,)*);
}
};
}
This pseudo code shows my goal:I am trying to populate a vector with enums of different types.
The main problem is that I don't know the index of the loop, so dispatch the proper value to the corresponding Args index.
Is it possible to do with macro rules ?
Thank you in advance for your help.