macro_rules! attributes {
() => {
#[cfg(true)]
};
}
macro_rules! struct_with_attrs {
() => {
attributes! {}
struct Foo;
};
}
struct_with_attrs! {}
I wanted to implement macro_rules!
with a similar syntax to the thiserror
crate, but I'm struggling with filtering out the custom directives in $(#[$meta])*
.
It would be super useful to be able to call a macro for each $meta
item to match on it, but this doesn't seem to be possible. Either macros are expanded in the wrong order, or can't even generate attributes, because they end up being a separate AST node.
Is there a trick for this, other than making the whole macro recursive?