A cargo plugin for showing a tree-like overview of a crate's modules.
With time, as your Rust projects grow bigger and bigger, it gets more and more important to properly structure your code. Fortunately Rust provides us with a quite sophisticated module system, allowing us to neatly split up our crates into arbitrarily small sub-modules of types and functions. While this helps to avoid monolithic and unstructured chunks of code, it can also make it hard at times to still mentally stay on top of the over-all high-level structure of the project at hand.
This is where cargo-modules
comes into play:
Install cargo-modules
on nightly via:
bash
cargo install cargo-modules
Or using rustup's ad-hoc mode:
bash
rustup run nightly cargo install cargo-modules
Or if you want to build it locally:
bash
$ rustup run nightly cargo build --release
cargo-modules requires nightly to run.
As such unless you already are using nightly
you need to either run this rustup command once,
to set the default toolchain to nightly
:
bash
rustup default nightly
… or override the toolchain for the current directory (again, once):
bash
rustup override set nightly
To then be able to just call cargo-modules through:
bash
cargo modules <options>
Or if you want to stay on the beta
or stable
toolchain you would have to call cargo-modules through:
bash
rustup run nightly cargo modules <options>
If you want to also list of potentially orphaned modules,
then add a --orphans
argument:
bash
cargo modules --orphans
Any file src/../foo.rs
or src/../foo/mod.rs
that is not linked by its
super
-module via mod foo;
is considered a (potential) orphaned module.
To keep false positives to a minimum cargo-modules
excludes all build scripts
as well as lib.rs
and main.rs
from the selection of potential orphans.
If you, for some reason, need to remove the coloring, use:
bash
cargo modules --plain
If you also want to see which modules depends on which other modules, you can use dot mode to output Graphviz DOT compatible output.
bash
cargo modules --dot
As extra options you can toggle external types/modules, conditional modules and used types using the --external
, --conditional
and --types
options respectively.
Dotted nodes are conditional (test modules for example).
Black edges denote a 'is sub module of' relation.
If you need any further help:
bash
cargo modules --help
Please read CONTRIBUTING.md for details on our code of conduct,
and the process for submitting pull requests to us.
We use SemVer for versioning. For the versions available, see the tags on this repository.
See also the list of contributors who participated in this project.
This project is licensed under the MPL-2.0 – see the LICENSE.md file for details.