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§
Provided Methods§
Sourcefn visit_statement(&mut self, stmt: &Statement<'a>) -> Result<Self::T, Self::E>
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.
Sourcefn visit_expression(
&mut self,
expr: &Expression<'a>,
) -> Result<Self::T, Self::E>
fn visit_expression( &mut self, expr: &Expression<'a>, ) -> Result<Self::T, Self::E>
Visit an Expression node. Recurses into all child expressions by default.
Sourcefn visit_select(&mut self, select: &Select<'a>) -> Result<Self::T, Self::E>
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.
Sourcefn visit_table_reference(
&mut self,
tr: &TableReference<'a>,
) -> Result<Self::T, Self::E>
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", so this trait is not object safe.