Skip to main content

Crate crawk

Crate crawk 

Source
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:

FileModule 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 use statements but also type annotations, trait bounds, struct patterns/literals, impl blocks, and macro invocations
  • Path expansion: Resolves self:: and super:: to absolute crate:: paths
  • Glob expansion: Optionally expands use crate::foo::* to explicit items
  • Test module filtering: Optionally include or exclude #[cfg(test)] modules
  • Depth limiting: Truncate TypeReference paths via TypeReference::truncate_to_depth

Modules§

version
Version and build information for the crawk crate.

Structs§

AnalysisOptions
Options for dependency analysis.
AnalysisResult
Result of analyzing a module’s dependencies.
Analyzer
Analyzer for Rust module dependencies.
ModuleInfo
A struct representing information about a Rust module, including its path and source file.
TargetInfo
Metadata identifying which compilation target a module belongs to.
TypeReference
Unified type reference representing any path/type usage in Rust code.

Enums§

AnalysisError
Error types for analysis operations.
GroupItem
Item within a grouped import {...}.
ModuleVisibility
Visibility of a Rust module as declared in source code.
PathPrefix
Prefix determining how path is resolved.
PathSuffix
Suffix determining how a path ends (alias, glob, or group).
TargetKind
The kind of compilation target a module belongs to.