cargo-typegraph generates Graphviz DOT dependency graphs for Rust types. It
can run as a Cargo subcommand (cargo typegraph) or as a standalone binary.
The graph includes local structs, enums, traits, and type aliases. Edges point from a type to the types referenced by its definition, fields, aliases, generics, bounds, and implementations. Nodes are colored by visibility so public, crate-visible, super-visible, restricted, and private types are easy to distinguish.
- A nightly Rust toolchain when generating rustdoc JSON directly, because rustdoc JSON currently uses unstable rustdoc options.
- Graphviz if you want to render the generated DOT output as SVG, PNG, or PDF.
From crates.io:
cargo install cargo-typegraphAfter installation, Cargo can invoke the binary as a subcommand:
cargo typegraph --helpGenerate a DOT graph for the current package:
cargo typegraph -o typegraph.dotRender the graph with Graphviz:
dot -Tsvg typegraph.dot -o typegraph.svgGenerate a graph for a specific package or binary:
cargo typegraph -p my_crate -o typegraph.dot
cargo typegraph --bin my_binary -o typegraph.dotRead an existing rustdoc JSON file instead of invoking cargo doc:
cargo typegraph --json target/doc/my_crate.json -o typegraph.dotInclude external referenced types as graph nodes:
cargo typegraph --include-external -o typegraph.dotDetect dependency cycles and fail when any are found:
cargo typegraph --detect-cycles -o typegraph.dotPass additional arguments through to cargo doc after --:
cargo typegraph -o typegraph.dot -- --workspace--json <PATH> Read an existing rustdoc JSON file
-o, --output <PATH> Write DOT to a file instead of stdout
--include-external Include referenced external types as graph nodes
--detect-cycles Print the first dependency cycle to stderr and exit with an error
--no-private Do not pass --document-private-items to cargo doc
--manifest-path <PATH> Cargo manifest path for cargo doc
-p, --package <PACKAGE> Package to document
--bin <NAME> Generate docs for a binary target
--target <TRIPLE> Cargo target triple
--features <FEATURES> Space or comma separated Cargo features
--all-features Activate all Cargo features
--no-default-features Disable default Cargo features
--toolchain <NAME> Use cargo +<NAME> doc (default: nightly)
-h, --help Print help
-V, --version Print version
DOT is written to standard output by default. Use -o or --output to write it
to a file.
By default, cargo-typegraph asks rustdoc to include private items so the graph
can describe internal type structure. Use --no-private when you only want the
types exposed by normal generated documentation.
Internally, cargo-typegraph builds graphs from rustdoc JSON. By default it
invokes cargo doc with the required rustdoc JSON options, but --json can
read an existing rustdoc JSON file directly.
This project is dedicated to the public domain under CC0 1.0. See
LICENSE for details.