Expand description
crawk - Rust module dependency analyzer
This library provides tools for analyzing module dependencies in Rust codebases.
It parses Rust source code to identify all internal crate references including
use statements, type annotations, trait bounds, struct literals, and macro invocations.
§Quick Start
let mut analyzer = Analyzer::new(Path::new("/path/to/crate"))?;
let options = AnalysisOptions::default();
let result = analyzer.analyze_module("utils::parser", &options)?;
for (module, refs) in result.dependencies() {
println!("{module}");
for reference in refs {
println!(" {reference}");
}
}§Key Concepts
§Module path
A module path is the :: separated path to a module within the crate, mirroring
the file layout under src/. For example:
| File | Module path |
|---|---|
src/lib.rs | (empty string) |
src/utils.rs | "utils" |
src/utils/parser.rs | "utils::parser" |
src/utils/parser/lexer.rs | "utils::parser::lexer" |
Inline modules (declared with mod foo { … } inside a file) are addressed by their
full path too, e.g. "utils::parser::tests" for a mod tests block inside
src/utils/parser.rs.
§Internal crate references
crawk reports internal crate references — paths that point to items defined inside
the analyzed crate itself, not to std or external dependencies. A path is considered
internal if it starts with crate::, self::, super::, or the crate’s own name.
All such paths are normalized to their canonical form before being returned.
§Relationship between Analyzer::new and analyze_module
Analyzer::new takes the crate root directory (the one containing
Cargo.toml) and initializes internal state. Analyzer::analyze_module
then takes a module path (see above) relative to that crate and returns its dependencies.
The same Analyzer instance can be reused to analyze multiple modules; it caches parsed
files internally to avoid redundant I/O.
§MSRV
Requires Rust 1.85 or later (edition = "2024").
§Features
- Comprehensive dependency detection: Captures not just
usestatements but also type annotations, trait bounds, struct patterns/literals, impl blocks, and macro invocations - Path expansion: Resolves
self::andsuper::to absolutecrate::paths - Glob expansion: Optionally expands
use crate::foo::*to explicit items - Test module filtering: Optionally include or exclude
#[cfg(test)]modules - Depth limiting: Truncate
TypeReferencepaths viaTypeReference::truncate_to_depth
Modules§
- version
- Version and build information for the crawk crate.
Structs§
- Analysis
Options - Options for dependency analysis.
- Analysis
Result - Result of analyzing a module’s dependencies.
- Analyzer
- Analyzer for Rust module dependencies.
- Module
Info - A struct representing information about a Rust module, including its path and source file.
- Target
Info - Metadata identifying which compilation target a module belongs to.
- Type
Reference - Unified type reference representing any path/type usage in Rust code.
Enums§
- Analysis
Error - Error types for analysis operations.
- Group
Item - Item within a grouped import
{...}. - Module
Visibility - Visibility of a Rust module as declared in source code.
- Path
Prefix - Prefix determining how path is resolved.
- Path
Suffix - Suffix determining how a path ends (alias, glob, or group).
- Target
Kind - The kind of compilation target a module belongs to.