# Map Rust source into a module tree

Paste Rust source and map its modules, structs, enums, traits, impl blocks, functions and visibility as a tree, Mermaid graph, JSON, or crate::path list.

## Run it

- **CLI:** `gizza tool rust-module-map "pub mod config {
    pub struct Config;
    impl Config { pub fn load() -> Self { Config } }
}

fn main() {}"`
- **Web:** https://gizza.ai/tools/rust-module-map/
- **Agents:** machine-readable descriptor (parameters JSON Schema) at https://gizza.ai/tools/rust-module-map/tool.json

## Inputs

- `source` — Rust source _(field)_
- `format` — Output format _(field)_
- `max_depth` — Maximum depth (0 = unlimited) _(field)_
- `focus_on` — Focus on module path _(field)_
- `sort_by` — Sort siblings by _(field)_
- `show_types` — Show types _(field)_
- `show_traits` — Show traits _(field)_
- `show_fns` — Show functions and methods _(field)_
- `show_impls` — Show impl blocks _(field)_
- `show_consts` — Show const/static items _(field)_
- `include_tests` — Include #[cfg(test)] and #[test] items _(field)_
- `show_visibility` — Show visibility annotations _(field)_
- `crate_name` — Crate root label _(field)_

## Output

- Module map (text)

## Query parameters

Open the tool pre-filled and auto-run via URL:

- `source` — Rust source
- `format` — Output format
- `max_depth` — Maximum depth (0 = unlimited)
- `focus_on` — Focus on module path
- `sort_by` — Sort siblings by
- `show_types` — Show types
- `show_traits` — Show traits
- `show_fns` — Show functions and methods
- `show_impls` — Show impl blocks
- `show_consts` — Show const/static items
- `include_tests` — Include #[cfg(test)] and #[test] items
- `show_visibility` — Show visibility annotations
- `crate_name` — Crate root label

Example: `https://gizza.ai/tools/rust-module-map/?source=pub%20mod%20config%20%7B%0A%20%20%20%20pub%20struct%20Config%3B%0A%20%20%20%20impl%20Config%20%7B%20pub%20fn%20load%28%29%20-%3E%20Self%20%7B%20Config%20%7D%20%7D%0A%7D%0A%0Afn%20main%28%29%20%7B%7D&format=tree&max_depth=0&focus_on=crate%3A%3Aconfig&sort_by=source&show_types=true&show_traits=true&show_fns=true&show_impls=true&show_consts=true&include_tests=true&show_visibility=true&crate_name=my_crate`

---

## About this tool

Rust crates grow a hierarchy quickly: `mod` declarations, nested modules, public and private types, traits, impl blocks, methods, tests, and constants all compete for attention. This tool turns pasted Rust source into a compact map of that hierarchy so you can understand a module before editing it, paste a quick graph into an issue, or export a machine-readable outline.

The parser is `syn`, not a brace-counting regex. That means inline modules, external `mod foo;` declarations, visibility such as `pub(crate)`, impl methods, trait declarations, `#[cfg(test)]`, and `#[test]` attributes are read from Rust syntax. For multi-file snippets, separate files with headers:

```text
=== src/lib.rs ===
pub mod util;

=== src/util.rs ===
pub fn slug() {}
```

### Worked example

Input:

```rust
pub mod config {
    pub struct Config;
    impl Config { pub fn load() -> Self { Config } }
}

pub trait Service { fn run(&self); }
fn main() {}
```

Default tree output:

```text
crate
├── mod config: pub
│   ├── struct Config: pub
│   └── impl Config
│       └── fn load: pub
├── trait Service: pub
└── fn main: pub(self)
```

Switch to Mermaid when you want a pasteable graph, JSON when another script needs counts and children, or paths when you want a grep-friendly list like `crate::config::Config::load  (fn, pub)`.

### Practical uses

- Review a copied `lib.rs` or module before making a change.
- Compare the public/private shape of a file before and after refactoring.
- Include `#[cfg(test)]` modules only when you need test helpers in the map.
- Focus on one subtree with `focus_on=crate::module`.
- Hide function nodes or type nodes to make a high-level diagram fit in a pull request comment.

### Limits and edge cases

- Input is capped at 512 KiB and module nesting at 64 levels.
- This maps the text you paste. It does not run `cargo metadata`, load files from disk, expand macros, resolve feature flags, or follow `#[path]` attributes.
- A `mod foo;` declaration is marked `(external)` unless a matching `=== src/foo.rs ===` or `=== src/foo/mod.rs ===` section is pasted too.
- `include_tests` is off by default, matching the usual source map view. Turn it on for `#[cfg(test)]` modules and `#[test]` functions.
- Mermaid output is plain text; paste it into Markdown or a Mermaid renderer to see the graph.

## FAQ

<details>
<summary>Does this inspect my local crate on disk?</summary>

No. It only parses the Rust text you paste into the form or pass to the CLI. That keeps the tool browser-only and deterministic, but it also means it cannot discover sibling files unless you include them in the paste with `=== path ===` headers.

</details>

<details>
<summary>How do I resolve `mod foo;` declarations?</summary>

Paste multiple files in one input. Start each file with a separator such as `=== src/lib.rs ===` or `=== src/foo.rs ===`. When the root declares `mod foo;`, the mapper connects the matching file under that module. If the file is missing, the node is shown as `(external)`.

</details>

<details>
<summary>Why are test modules hidden?</summary>

Most module maps are used to understand production structure, so `#[cfg(test)]`, `#[test]`, and `#[bench]` items are excluded by default. Enable `include_tests` when you want test helpers and test-only modules included in the tree.

</details>

<details>
<summary>Can it show dependency edges between modules?</summary>

No. This tool maps declarations and nesting. Dependency edges require name/import analysis across files and are already covered by graph-oriented code tools. Use Mermaid output here for the declaration hierarchy, not for `use` dependency cycles.

</details>

<details>
<summary>Why does a macro-generated item not appear?</summary>

Macros are not expanded. A visible `macro_rules! name` definition appears as a macro node, but items generated by invoking that macro are not available to `syn` without running a compiler expansion pipeline.

</details>

## Related tools

- [Strip accents and transliterate text to plain ASCII](https://gizza.ai/tools/accent-stripper/): Paste text and strip accents to plain ASCII. Transliterate non-Latin scripts, preserve chosen characters, lowercase, and audit unmapped output.
- [Brotli Decompress](https://gizza.ai/tools/brotli-decompress/): Paste a Brotli (.br) payload as Base64 or hex and read what's inside. Output as text, hex, or Base64, with size and ratio stats. Free, private, no sign-up.
- [Child Growth Percentile Calculator](https://gizza.ai/tools/child-growth-percentile/): Compute CDC child growth-chart percentiles and z-scores from age, sex, height, weight and head circumference. Supports metric or US units.
- [Dependency Risk Auditor](https://gizza.ai/tools/dependency-risk-auditor/): Audit a package.json, package-lock.json, yarn.lock or pnpm-lock.yaml for wildcard versions, git/URL deps, install scripts and missing integrity hashes.
- [DNA / RNA Reverse Complement](https://gizza.ai/tools/dna-reverse-complement/): Reverse-complement DNA or RNA in your browser — full IUPAC ambiguity codes, FASTA records, preserved case, complement-only and reverse-only modes. No upload.
