AstParser

Struct AstParser 

Source
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

Source

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
Source

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.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.