| Crates.io | codegraph-rust |
| lib.rs | codegraph-rust |
| version | 0.1.2 |
| created_at | 2025-11-06 03:47:05.932141+00 |
| updated_at | 2026-01-02 00:24:29.137594+00 |
| description | Rust parser for CodeGraph - extracts code entities and relationships from Rust source files |
| homepage | |
| repository | https://github.com/anvanster/codegraph |
| max_upload_size | |
| id | 1919034 |
| size | 108,005 |
Rust parser for CodeGraph - extracts code entities and relationships from Rust source files.
codegraph-parser-apiParserConfigAdd to your Cargo.toml:
[dependencies]
codegraph = "0.1"
codegraph-rust = "0.1"
codegraph-parser-api = "0.1"
use codegraph::CodeGraph;
use codegraph_parser_api::CodeParser;
use codegraph_rust::RustParser;
use std::path::Path;
fn main() -> Result<(), Box<dyn std::error::Error>> {
// Create an in-memory graph
let mut graph = CodeGraph::in_memory()?;
// Create the parser
let parser = RustParser::new();
// Parse a Rust file
let file_info = parser.parse_file(
Path::new("src/main.rs"),
&mut graph
)?;
println!("Parsed {} functions", file_info.functions.len());
println!("Parsed {} structs/enums", file_info.classes.len());
println!("Parsed {} traits", file_info.traits.len());
Ok(())
}
use codegraph::CodeGraph;
use codegraph_parser_api::CodeParser;
use codegraph_rust::RustParser;
use std::path::Path;
let source = r#"
pub struct Person {
pub name: String,
age: u32,
}
impl Person {
pub fn new(name: String, age: u32) -> Self {
Self { name, age }
}
}
"#;
let mut graph = CodeGraph::in_memory()?;
let parser = RustParser::new();
let info = parser.parse_source(source, Path::new("person.rs"), &mut graph)?;
# Ok::<(), Box<dyn std::error::Error>>(())
use codegraph_parser_api::ParserConfig;
use codegraph_rust::RustParser;
let config = ParserConfig::default()
.with_max_file_size(5 * 1024 * 1024) // 5 MB
.with_parallel(true);
let parser = RustParser::with_config(config);
use codegraph::CodeGraph;
use codegraph_parser_api::CodeParser;
use codegraph_rust::RustParser;
use std::path::PathBuf;
let mut graph = CodeGraph::in_memory()?;
let parser = RustParser::new();
let files = vec![
PathBuf::from("src/main.rs"),
PathBuf::from("src/lib.rs"),
PathBuf::from("src/utils.rs"),
];
let project_info = parser.parse_files(&files, &mut graph)?;
println!("Total functions: {}", project_info.total_functions);
println!("Total classes: {}", project_info.total_classes);
println!("Success rate: {:.1}%", project_info.success_rate() * 100.0);
# Ok::<(), Box<dyn std::error::Error>>(())
use codegraph::CodeGraph;
use codegraph_parser_api::CodeParser;
use codegraph_rust::RustParser;
use std::path::Path;
let mut graph = CodeGraph::in_memory()?;
let parser = RustParser::new();
// Parse all .rs files in src/ directory recursively
let project_info = parser.parse_directory(
Path::new("src"),
&mut graph
)?;
println!("Parsed {} files", project_info.files.len());
# Ok::<(), Box<dyn std::error::Error>>(())
/// and //!)The parser respects all ParserConfig options:
pub struct ParserConfig {
pub skip_private: bool, // Skip private items
pub skip_tests: bool, // Skip #[test] functions
pub max_file_size: usize, // Maximum file size to parse
pub timeout_per_file: Option<Duration>, // Timeout per file
pub parallel: bool, // Enable parallel parsing
pub include_docs: bool, // Extract documentation
pub extract_types: bool, // Extract type information
}
The parser creates the following node types in the graph:
And the following edge types:
The parser uses the syn crate for Rust parsing, which is fast and battle-tested:
Enable parallel parsing for large projects:
let config = ParserConfig::default().with_parallel(true);
let parser = RustParser::with_config(config);
See the tests/ directory for comprehensive examples.
Apache-2.0
Contributions are welcome! Please see the main CodeGraph repository for guidelines.