cargo-macra 0.1.1

CLI for working with macro expansion and diagnostics in Rust projects.
cargo-macra-0.1.1 is not a library.

cargo-macra Latest Version Documentation GitHub Actions

Interactive Rust macro expansion viewer with a terminal UI.

Motivation

cargo-macra is focused on understanding and debugging macro-heavy Rust code incrementally. Instead of dumping all expanded code at once, it lets you step through expansions in source context, which is useful for:

  • learning how macro expansion works
  • debugging complex macro crates where one macro expands into more macro calls
  • investigating specific macro invocations when tools like rust-analyzer expandMacro or cargo expand are too all-at-once for practical debugging

Screenshot

asciicast

Install

From crates.io (when published)

cargo install cargo-macra

From source

git clone https://github.com/yasuo-ozu/macra.git
cd macra
cargo install --path .

Usage

As a cargo subcommand:

cargo macra --manifest-path /path/to/Cargo.toml

Direct binary invocation:

cargo-macra --manifest-path /path/to/Cargo.toml

Open a specific module first:

cargo macra --manifest-path /path/to/Cargo.toml foo::bar

Print traced expansions without launching TUI:

cargo macra --manifest-path /path/to/Cargo.toml --show-expansion

CLI Options

Usage: cargo macra [OPTIONS] [MODULE] [CARGO_ARGS]...

Arguments:
  [MODULE]         Module path to open (e.g., "foo::bar")
  [CARGO_ARGS]...  Additional arguments to pass to cargo

Options:
  -p, --package <PACKAGE>              Package to check
      --bin <BIN>                      Build only the specified binary
      --lib                            Build only the specified library
      --test <TEST>                    Build only the specified test target
      --example <EXAMPLE>              Build only the specified example
      --manifest-path <MANIFEST_PATH>  Path to Cargo.toml
      --show-expansion                 Print expansions and exit
  -h, --help                           Print help

TUI Keys

  • j / k, Up / Down: Move cursor
  • g / G, Home / End: Jump top/bottom
  • n / N: Jump next/previous macro
  • Enter: Expand/collapse macro or enter mod file
  • Backspace: Return to parent module
  • Tab / Shift+Tab: Move tree selection
  • Space: Toggle child visibility in macro tree
  • r: Reload trace data
  • q / Esc: Quit

Development

cargo build
cargo test

License

MIT (stub files included in this repository; fill in copyright owner/year).