pub struct AstParser;Expand description
AST (Abstract Syntax Tree) parser for Rust source files.
The AstParser uses the syn crate to parse Rust source code into an abstract syntax tree,
which can then be analyzed to extract route definitions, type information, and other metadata.
§Example
use openapi_from_source::parser::AstParser;
use std::path::Path;
let parsed = AstParser::parse_file(Path::new("src/main.rs")).unwrap();
println!("Parsed {} items", parsed.syntax_tree.items.len());Implementations§
Source§impl AstParser
impl AstParser
Sourcepub fn parse_file(path: &Path) -> Result<ParsedFile>
pub fn parse_file(path: &Path) -> Result<ParsedFile>
Parses a single Rust source file into an AST.
This method reads the file content and uses syn::parse_file to parse it into
a syntax tree. If parsing fails (e.g., due to syntax errors), an error is returned.
§Arguments
path- Path to the Rust source file to parse
§Returns
Returns a ParsedFile containing the file path and syntax tree on success.
§Errors
Returns an error if:
- The file cannot be read
- The file contains invalid Rust syntax
Sourcepub fn parse_files(paths: &[PathBuf]) -> Vec<Result<ParsedFile>> ⓘ
pub fn parse_files(paths: &[PathBuf]) -> Vec<Result<ParsedFile>> ⓘ
Parses multiple Rust source files, continuing even if some fail.
This method attempts to parse all provided files, collecting both successes and failures. Files that fail to parse are logged as warnings, but parsing continues for remaining files. This allows the tool to generate partial documentation even when some files have syntax errors.
§Arguments
paths- Slice of file paths to parse
§Returns
Returns a vector of Result<ParsedFile>, one for each input path. Successful parses
contain Ok(ParsedFile), while failures contain Err with error details.