cargo-expand icon indicating copy to clipboard operation
cargo-expand copied to clipboard

Expand only macros that come from a specific crate

Open dr-bonez opened this issue 5 years ago • 4 comments

Would be good to be able to only expand specific macros and leave other source as is.

i.e.: cargo expand --crate="my-crate-derive"

or cargo expand --derive=MyTraitA,MyTraitB

at the very least would be good to not expand macros that come from std.

dr-bonez avatar Sep 06 '19 22:09 dr-bonez

This would be a game-changer, because it would allow you to use cargo-expand to "inline" utility macros like thiserror.

Right now a lot of manual effort is required to do this, because you either have to reimplement the macro functionality in plain code yourself or, if you're using cargo-expand, go through all the expanded stdlib macros (println! and family) and un-expand them.

So yeah, that would be pretty damn cool and make this tool like, at least twice more useful

kangalio avatar Nov 05 '20 17:11 kangalio

I would accept a PR to implement this.

dtolnay avatar Sep 02 '21 06:09 dtolnay

This would be incredible! When developing macros I have to fix up all the expanded panics, format!'s, etc. It would be great if I could only expand a specific macro.

$ cargo expand utils::some_util --macro tokio::main

tqwewe avatar Apr 13 '22 08:04 tqwewe