Skip to content
Arxo Arxo

Rust Language Support

This document describes the Rust language parsing support in Arxo.

Arxo now supports analyzing Rust codebases, extracting import graphs, call graphs, and detecting side effects. Rust support works alongside TypeScript support, enabling analysis of mixed-language projects.

  • use statements: Extracts all use declarations (e.g., use crate::foo;, use std::io;)
  • mod declarations: Tracks module dependencies (e.g., mod bar;, pub mod baz;)
  • Re-exports: Detects pub use statements
  • Module resolution: Resolves Rust module paths to file paths:
    • crate::foosrc/foo.rs or src/foo/mod.rs
    • super::bar → parent module’s bar.rs
    • self::baz → current module’s baz.rs
  • Function calls: Extracts direct function calls (e.g., foo(), crate::bar::baz())
  • Method calls: Tracks method invocations (e.g., obj.method())
  • Macro invocations: Detects macro calls (e.g., println!(), vec![])

Detects side effects in Rust code:

  • I/O: std::fs::*, std::io::*, tokio::fs::*
  • Network: std::net::*, tokio::net::*, HTTP clients (reqwest, ureq, etc.)
  • Storage: Database clients (sqlx, diesel, etc.)
  • Logging: println!, eprintln!, log, tracing
  • Time: std::time::*, tokio::time::*, chrono
  • Random: rand, std::rand
  • Mutation: unsafe blocks, static mut, RefCell, Mutex, RwLock

You can specify the language in your config file:

data:
language: rust # Options: "typescript", "rust", or "auto"
import_graph:
group_by: folder
group_depth: 2
exclude:
- target
- node_modules

If language: auto is specified (the default), Arxo will:

  1. Scan the project directory for file extensions
  2. Detect which languages are present (.rs for Rust, .ts/.tsx for TypeScript)
  3. Parse all detected languages and merge their graphs

Arxo supports analyzing projects with both TypeScript and Rust:

data:
language: auto # Will detect and parse both languages
import_graph:
exclude:
- target # Rust build artifacts
- node_modules # TypeScript dependencies

Rust module resolution follows these rules:

  1. Crate-relative paths (crate::foo):

    • Resolved relative to the crate root (where Cargo.toml is located)
    • Looks for src/foo.rs or src/foo/mod.rs
  2. Super paths (super::bar):

    • Resolved relative to the parent module
    • Goes up one directory level
  3. Self paths (self::baz):

    • Resolved relative to the current module
    • Looks in the same directory
  4. External crates (std::io, serde::Serialize):

    • Currently not resolved (external dependencies)
    • May be added in future versions

For Cargo workspaces, Arxo:

  • Parses the root Cargo.toml to identify workspace members
  • Resolves module paths within each workspace member
  • Tracks dependencies between workspace crates
  1. Macro expansion: Macros are parsed as-is without expansion. Generated code is not analyzed.

  2. Trait resolution: Method calls via traits use name-based matching. Full trait resolution is not yet implemented.

  3. Conditional compilation: #[cfg(...)] attributes are not processed. All code is analyzed regardless of feature flags.

  4. Cross-language edges: TypeScript and Rust graphs are kept separate. Cross-language dependencies (e.g., via WASM/FFI) are not yet tracked.

  5. External crates: Dependencies from Cargo.toml are not resolved. Only internal module paths are tracked.

  • Full trait method resolution
  • Macro expansion support (optional)
  • Conditional compilation awareness
  • Cross-language dependency tracking (WASM/FFI)
  • External crate resolution via Cargo.toml
Terminal window
# Create config.yaml
cat > config.yaml << EOF
data:
language: rust
import_graph:
group_by: folder
group_depth: 2
exclude:
- target
metrics:
- id: scc
enabled: true
- id: ricci_curvature
enabled: true
report:
format: html
file: rust-analysis.html
EOF
# Run analysis
arxo analyze --path /path/to/rust/project --config config.yaml
Terminal window
# Auto-detect both languages
cat > config.yaml << EOF
data:
language: auto
import_graph:
exclude:
- target
- node_modules
EOF
arxo analyze --path /path/to/mixed/project --config config.yaml

Rust parsing uses the syn crate, the standard Rust parser used by procedural macros. This provides:

  • Full Rust syntax support
  • Accurate AST representation
  • Compatibility with all Rust language features

Rust’s module system is more complex than TypeScript’s:

  • Modules can be declared in two ways: mod foo; (file) or mod foo { ... } (inline)
  • File-based modules can be foo.rs or foo/mod.rs
  • Visibility modifiers (pub, pub(crate), etc.) affect dependency tracking

Arxo handles these complexities by:

  • Detecting both module declaration styles
  • Resolving file paths using Rust’s standard module resolution rules
  • Tracking public vs. private modules for accurate dependency graphs

If modules aren’t being resolved correctly:

  1. Check Cargo.toml: Ensure the project has a valid Cargo.toml at the root
  2. Verify file structure: Rust modules must follow the standard structure (src/ directory, etc.)
  3. Check excludes: Ensure target/ is in your exclude list to avoid parsing build artifacts

If you see parsing errors:

  1. Syntax errors: Arxo will skip files with syntax errors and log warnings
  2. Unsupported features: Some advanced Rust features may not be fully supported yet
  3. Check logs: Review error messages to identify problematic files