I try to generate a struct from a macro looking like that:
decl_struct! {
MyStruct {
mut foo,
const bar,
}
}
The thing is that I want to filter out the fields marked as const. I have tried with the following code, but it does not function due to the fact that the outer macro is evaluated first:
macro_rules! decl_struct {
{
$name:ident {
$( $kind:ident $member:ident, )*
}
} => {
decl_struct!(@gen_struct $name { $( decl_struct!(@gen_struct_member $kind $member) )* } );
};
// Filters the `const` members out:
(@gen_struct_member mut $member:ident) => ($member,);
(@gen_struct_member const $member:ident) => ();
// Generate the whole struct:
{
@gen_struct $name:ident {
$( $member:ident, )*
}
} => {
struct $name {
$( $member:ident : u32 /*Dummy type*/, )*
}
};
}
decl_struct! {
MyStruct {
mut foo,
const bar,
}
}
What can be an alternative approach?