Is there a way to list modules in my crate using cargo?

I'm playing around with where best to host and reference code generated in a build.rs. Cargo can be used with rustdoc by way of cargo doc. In the grand-scheme of what rustdoc accomplishes, it generates a tree of how the modules relate to each other.

Is there a cargo command that outputs the module structure of the crate? I could not find anything in the docs nor --help but suspect there might be a way. I could have missed something. Is anyone aware of this capability?

You could use the cargo modules sub-command.

$ cargo install cargo-modules
$ cargo modules generate tree

crate hotg_rune_compiler
ā”œā”€ā”€ mod asset_loader: pub
ā”‚   ā””ā”€ā”€ mod builtin: pub(self) #[cfg(feature = "builtins")]
ā”œā”€ā”€ mod codegen: pub
ā”‚   ā””ā”€ā”€ mod query: pub(self)
ā”œā”€ā”€ mod config: pub(crate)
ā”œā”€ā”€ mod im: pub
ā”œā”€ā”€ mod parse: pub
ā”‚   ā”œā”€ā”€ mod query: pub(self)
ā”‚   ā””ā”€ā”€ mod yaml: pub
ā”‚       ā””ā”€ā”€ mod document_serde: pub(self)
ā””ā”€ā”€ mod type_check: pub
    ā””ā”€ā”€ mod types: pub(self)
3 Likes