Crates.io | dep_graph_rs |
lib.rs | dep_graph_rs |
version | 0.2.0 |
created_at | 2025-07-15 15:52:52.946933+00 |
updated_at | 2025-07-20 06:41:09.076854+00 |
description | Visualize/analyze a Rust crate's internal dependencies |
homepage | https://github.com/pseitz/dep_graph_rs |
repository | https://github.com/pseitz/dep_graph_rs |
max_upload_size | |
id | 1753521 |
size | 39,511 |
dep_graph_rs
generates a dependency graph for the internal modules of a Rust crate.
It uses the syn
crate to parse Rust source code and
analyzes use crate::...
statements to build a directed graph of dependencies between modules or files.
The graph is then output in the DOT language.
Note: This tool visualizes dependencies within a single crate. It does not show dependencies on external crates from Cargo.toml
.
One of the main motivations for this tool is to assist refactoring and understand dependencies.
My use case is to analyze the dependencies of a module before extracting it into a separate crate.
In this case, extracting tantivy/src/directory
into a new tantivy-directory
crate.
In this case we want to see on which other modules the directory
module depends:
dep_graph_rs tantivy_folder --source "directory.*" > tantivy_directory_deps.dot
You can install the tool using cargo
:
cargo install dep_graph_rs
To generate a dependency graph, run the tool with the path to your crate's root (src/lib.rs
or src/main.rs
):
dep_graph_rs <path-to-your-project|path-to-entry-file> > graph.dot
This will output the graph in DOT format to graph.dot
.
You can render the generated graph.dot
file in a few ways:
graph.dot
into an online viewer like GraphvizOnline.dot
command to render the graph to an image:
dot -Tpng graph.dot -o graph.png
--mode <file|module>
: Group the graph by file or by module (default: module
).--source <regex>
: Filter by source module/file.--destination <regex>
: Filter by destination module/file.--item <regex>
: Filter by the name of the imported item (e.g., a function or struct).For example, to only show dependencies originating from the graphics
module:
dep_graph_rs ./test_proj1 --source "graphics" > graph.dot
*
importsrust_analyzer
territory, e.g. find_references etc.?