pub struct RustParser;Expand description
Rust source code parser using syn for AST analysis.
Provides static methods for parsing Rust source files and extracting structural information about the code.
Implementations§
Source§impl RustParser
impl RustParser
Sourcepub fn parse_rust_file(file_path: &str, content: &str) -> Result<RustAnalysis>
pub fn parse_rust_file(file_path: &str, content: &str) -> Result<RustAnalysis>
Parses a Rust source file and extracts structural information.
This method uses the syn crate to parse Rust source code into an AST
and then extracts information about modules, functions, structs, enums,
and implementations.
§Arguments
file_path- Path to the file being parsed (used for error reporting)content- Source code content as a string
§Returns
A RustAnalysis containing all extracted structural information.
§Errors
Returns an error if the source code cannot be parsed as valid Rust syntax.
§Examples
use ai_context_gen::parser::RustParser;
let source = r#"
pub struct MyStruct {
pub field: String,
}
impl MyStruct {
pub fn new() -> Self {
Self { field: String::new() }
}
}
"#;
let analysis = RustParser::parse_rust_file("example.rs", source).unwrap();
assert_eq!(analysis.structs.len(), 1);
assert_eq!(analysis.implementations.len(), 1);Auto Trait Implementations§
impl Freeze for RustParser
impl RefUnwindSafe for RustParser
impl Send for RustParser
impl Sync for RustParser
impl Unpin for RustParser
impl UnwindSafe for RustParser
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more