Skip to main content

Visitor

Trait Visitor 

Source
pub trait Visitor<'a>: Sized {
    type T: Default;
    type E;

    // Provided methods
    fn visit_statement(
        &mut self,
        stmt: &Statement<'a>,
    ) -> Result<Self::T, Self::E> { ... }
    fn visit_expression(
        &mut self,
        expr: &Expression<'a>,
    ) -> Result<Self::T, Self::E> { ... }
    fn visit_select(&mut self, select: &Select<'a>) -> Result<Self::T, Self::E> { ... }
    fn visit_table_reference(
        &mut self,
        tr: &TableReference<'a>,
    ) -> Result<Self::T, Self::E> { ... }
}
Expand description

Visitor pattern for traversing the AST.

Each visit_* method recursively walks the node’s children by default via the corresponding public walk_* free function. Override individual methods to observe or transform specific node kinds, then call the walk_* function to continue the descent.

§Return type

Every method returns Result<Self::T, Self::E>. T: Default allows walk functions to return a value even when visiting many children and discarding each intermediate result - they simply return Ok(T::default()) after processing all children. For pure side-effects set T = (). For early-termination, encode the “found” value in E and short-circuit with Err(...).

Required Associated Types§

Source

type T: Default

The success value produced when visiting a node.

Source

type E

The error / early-exit value.

Provided Methods§

Source

fn visit_statement(&mut self, stmt: &Statement<'a>) -> Result<Self::T, Self::E>

Visit a Statement node. Recurses into all child statements and expressions by default.

Source

fn visit_expression( &mut self, expr: &Expression<'a>, ) -> Result<Self::T, Self::E>

Visit an Expression node. Recurses into all child expressions by default.

Source

fn visit_select(&mut self, select: &Select<'a>) -> Result<Self::T, Self::E>

Visit a Select node. Recurses into all select expressions, table references, and clause expressions (WHERE, GROUP BY, HAVING, ORDER BY, LIMIT, etc.) by default.

Source

fn visit_table_reference( &mut self, tr: &TableReference<'a>, ) -> Result<Self::T, Self::E>

Visit a TableReference node. Recurses into subqueries, JOIN children, and any expressions (JSON path, function arguments, ON clause) by default.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§