pub trait ExpressionVisitor<E: ExprVisitable = Expr>: Sized {
// Required method
fn pre_visit(self, expr: &E) -> Result<Recursion<Self>>
where Self: ExpressionVisitor;
// Provided method
fn post_visit(self, _expr: &E) -> Result<Self> { ... }
}
Expand description
Implements the visitor
pattern for recursively walking Expr
s.
ExpressionVisitor
allows keeping the algorithms
separate from the code to traverse the structure of the Expr
tree and makes it easier to add new types of expressions and
algorithms by.
When passed toExpr::accept
, ExpressionVisitor::pre_visit
and ExpressionVisitor::post_visit
are invoked recursively
on all nodes of an expression tree.
For an expression tree such as
BinaryExpr (GT)
left: Column("foo")
right: Column("bar")
The nodes are visited using the following order
pre_visit(BinaryExpr(GT))
pre_visit(Column("foo"))
post_visit(Column("foo"))
pre_visit(Column("bar"))
post_visit(Column("bar"))
post_visit(BinaryExpr(GT))
If an Err
result is returned, recursion is stopped
immediately.
If Recursion::Stop
is returned on a call to pre_visit, no
children of that expression are visited, nor is post_visit
called on that expression
See Also:
Expr::accept
to drive a visitor through anExpr
- inspect_expr_pre: For visiting
Expr
s using functions
Required Methods§
Provided Methods§
sourcefn post_visit(self, _expr: &E) -> Result<Self>
fn post_visit(self, _expr: &E) -> Result<Self>
Invoked after all children of expr
are visited. Default
implementation does nothing.