Hacker News new | ask | show | jobs
by mamcx 10 days ago
yeah, lets be clear:

Most of the proc macros non-sense is to be able to annotate the enum or struct without wrapping it.

So that is why I use this hack:

https://docs.rs/macro_rules_attribute/0.2.2/macro_rules_attr...

P.D: Is there a true actually reason for proc-macros apart for this weird restriction?? And even if yes, how much nice things will be if this kind of scenario was already present so most not need to reach for proc-macros

3 comments

Types and generics are hard to parse in regular macros without a tt muncher. Ditto for fn args. If you need to do actual matching of types, you can't capture them as $xxx:ty because Rust will not allow a larger matched token to be broken up again (unless you use a paste! hack to roundtrip it back into ungrouped tokens).

I wrote https://crates.io/crates/type-mapper as a way to work around those limitations but it is _very_ painful TBH.

What this crate offers was RFC'd somewhat recently (https://github.com/rust-lang/rfcs/pull/3698, https://github.com/rust-lang/rfcs/pull/3697) and already available on nightly.
That's really cool, I was not familiar with this and will look into it!