Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to get the expansion of a single macro instead of the whole file?

I just found How do I see the expanded macro code that's causing my compile error?. Is it possible to get the expansion of a single macro instead of the whole file?

like image 273
bertfred Avatar asked Aug 19 '18 11:08

bertfred


2 Answers

The cargo-expand command is really just a thin wrapper around cargo rustc -- -Zunstable-options --pretty=expanded, which is itself a blunt instrument. You can't target a specific macro.

However, since version 0.4, you can reduce some noise by specifying an extra path argument to expand only macros used by that module:

$ cargo expand path::to::module
like image 193
Peter Hall Avatar answered Sep 22 '22 13:09

Peter Hall


"Show expanded macro" and "Show recursively expanded macro" commands were recently added to IntelliJ Rust.

A gif demo from CLion blog post:

Demo

like image 36
ozkriff Avatar answered Sep 23 '22 13:09

ozkriff