| Crates.io | rusty-ast |
| lib.rs | rusty-ast |
| version | 0.0.8 |
| created_at | 2025-02-25 22:08:31.763208+00 |
| updated_at | 2025-03-21 13:44:35.139968+00 |
| description | A tool that analyzes Rust code and visualizes its AST |
| homepage | |
| repository | https://github.com/katsuhirohonda/rusty-ast |
| max_upload_size | |
| id | 1569731 |
| size | 63,994 |
A Rust Abstract Syntax Tree (AST) visualization tool. This tool parses Rust source code and displays its syntactic structure in text or JSON format.
Install using Cargo:
cargo install rusty-ast
Or clone and build from this repository:
git clone https://github.com/e-bebe/rusty-ast.git
cd rusty-ast
cargo build --release
Basic usage:
# Parse a Rust source file
rusty-ast -f path/to/your/file.rs
# Parse Rust code directly
rusty-ast -c "fn main() { println!(\"Hello, world!\"); }"
# Process a directory (non-recursive)
rusty-ast -d path/to/your/project
# Process a directory recursively
rusty-ast -d path/to/your/project -r
# Output in JSON format
rusty-ast -f path/to/your/file.rs -o json
Command line options:
OPTIONS:
-c, --code <CODE> Rust code to parse (string)
-d, --directory <DIRECTORY> Directory containing Rust files to parse
-f, --file <FILE> Path to the Rust source file to parse
-h, --help Print help information
-o, --format <FORMAT> Output format (text or json) [default: text]
-r, --recursive Recursively process directories (only applies with --directory)
-V, --version Print version information
Add to your Cargo.toml:
cargo add rusty-ast
Example code:
use rusty_ast::{parse_rust_source, TextVisitor};
use syn::visit::Visit;
fn main() {
let code = r#"
fn add(a: i32, b: i32) -> i32 {
a + b
}
"#;
if let Ok(ast) = parse_rust_source(code) {
// Display AST in text format
let mut visitor = TextVisitor::new();
visitor.visit_file(&ast);
}
}
MIT
Contributions are welcome, including bug reports, feature requests, and pull requests.