Rust Language Support
Rust Language Support
Section titled “Rust Language Support”This document describes the Rust language parsing support in Arxo.
Overview
Section titled “Overview”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.
Features
Section titled “Features”Import Graph Analysis
Section titled “Import Graph Analysis”usestatements: Extracts allusedeclarations (e.g.,use crate::foo;,use std::io;)moddeclarations: Tracks module dependencies (e.g.,mod bar;,pub mod baz;)- Re-exports: Detects
pub usestatements - Module resolution: Resolves Rust module paths to file paths:
crate::foo→src/foo.rsorsrc/foo/mod.rssuper::bar→ parent module’sbar.rsself::baz→ current module’sbaz.rs
Call Graph Analysis
Section titled “Call Graph Analysis”- 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![])
Effect Detection
Section titled “Effect Detection”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:
unsafeblocks,static mut,RefCell,Mutex,RwLock
Configuration
Section titled “Configuration”Language Selection
Section titled “Language Selection”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_modulesAuto-Detection
Section titled “Auto-Detection”If language: auto is specified (the default), Arxo will:
- Scan the project directory for file extensions
- Detect which languages are present (
.rsfor Rust,.ts/.tsxfor TypeScript) - Parse all detected languages and merge their graphs
Mixed-Language Projects
Section titled “Mixed-Language Projects”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 dependenciesModule Resolution
Section titled “Module Resolution”Rust module resolution follows these rules:
-
Crate-relative paths (
crate::foo):- Resolved relative to the crate root (where
Cargo.tomlis located) - Looks for
src/foo.rsorsrc/foo/mod.rs
- Resolved relative to the crate root (where
-
Super paths (
super::bar):- Resolved relative to the parent module
- Goes up one directory level
-
Self paths (
self::baz):- Resolved relative to the current module
- Looks in the same directory
-
External crates (
std::io,serde::Serialize):- Currently not resolved (external dependencies)
- May be added in future versions
Workspace Support
Section titled “Workspace Support”For Cargo workspaces, Arxo:
- Parses the root
Cargo.tomlto identify workspace members - Resolves module paths within each workspace member
- Tracks dependencies between workspace crates
Limitations
Section titled “Limitations”Current Limitations
Section titled “Current Limitations”-
Macro expansion: Macros are parsed as-is without expansion. Generated code is not analyzed.
-
Trait resolution: Method calls via traits use name-based matching. Full trait resolution is not yet implemented.
-
Conditional compilation:
#[cfg(...)]attributes are not processed. All code is analyzed regardless of feature flags. -
Cross-language edges: TypeScript and Rust graphs are kept separate. Cross-language dependencies (e.g., via WASM/FFI) are not yet tracked.
-
External crates: Dependencies from
Cargo.tomlare not resolved. Only internal module paths are tracked.
Future Enhancements
Section titled “Future Enhancements”- Full trait method resolution
- Macro expansion support (optional)
- Conditional compilation awareness
- Cross-language dependency tracking (WASM/FFI)
- External crate resolution via
Cargo.toml
Example Usage
Section titled “Example Usage”Analyzing a Rust Project
Section titled “Analyzing a Rust Project”# Create config.yamlcat > config.yaml << EOFdata: 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.htmlEOF
# Run analysisarxo analyze --path /path/to/rust/project --config config.yamlAnalyzing a Mixed Project
Section titled “Analyzing a Mixed Project”# Auto-detect both languagescat > config.yaml << EOFdata: language: auto import_graph: exclude: - target - node_modulesEOF
arxo analyze --path /path/to/mixed/project --config config.yamlTechnical Details
Section titled “Technical Details”Parser
Section titled “Parser”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
Module System
Section titled “Module System”Rust’s module system is more complex than TypeScript’s:
- Modules can be declared in two ways:
mod foo;(file) ormod foo { ... }(inline) - File-based modules can be
foo.rsorfoo/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
Troubleshooting
Section titled “Troubleshooting”Module Resolution Issues
Section titled “Module Resolution Issues”If modules aren’t being resolved correctly:
- Check Cargo.toml: Ensure the project has a valid
Cargo.tomlat the root - Verify file structure: Rust modules must follow the standard structure (
src/directory, etc.) - Check excludes: Ensure
target/is in your exclude list to avoid parsing build artifacts
Parsing Errors
Section titled “Parsing Errors”If you see parsing errors:
- Syntax errors: Arxo will skip files with syntax errors and log warnings
- Unsupported features: Some advanced Rust features may not be fully supported yet
- Check logs: Review error messages to identify problematic files
Related Documentation
Section titled “Related Documentation”- Metrics Documentation — All metrics work with Rust code
- Plugin Development — Create custom metrics for Rust-specific analysis
- Configuration — General configuration options