Show HN: macro_magic – access foreign item tokens in Rust proc/attribute macros
crates.io
crates.io
This approach enables some very exotic functionality that is normally impossible in rust proc macros, where you can decorate an item _anywhere_ with your attribute macro, and that item's tokens will become accessible when referenced by path as part of the input to any macro_magic-amplified proc or attribute macro.
macro_magic is able to do all of this without violating the golden principle of proc macros (that they must be a pure function of their inputs), and without relying on improper methods such as IO bookkeeping or global state. It is purely based on decl macro callbacks calling each other and is perfectly valid, pure rust.
Some crates/ecosystems making use of macro_magic already include:
- https://crates.io/crates/supertrait (enables default associated types in stable rust)
- https://github.com/paritytech/polkadot-sdk
Happy to answer any questions anyone may have about macro_magic!
Also worth noting, I am on the job market looking for my next Rust and/or CTO position :) -- info in bio
Here is the first place such a thing was seen in the wild: https://github.com/paritytech/polkadot-sdk/blob/d0fd2660031b...