pub trait ExpressionWalk {
// Required methods
fn dfs(&self) -> DfsIter<'_> ⓘ;
fn bfs(&self) -> BfsIter<'_> ⓘ;
fn find<F>(&self, predicate: F) -> Option<&Expression>
where F: Fn(&Expression) -> bool;
fn find_all<F>(&self, predicate: F) -> Vec<&Expression>
where F: Fn(&Expression) -> bool;
fn contains<F>(&self, predicate: F) -> bool
where F: Fn(&Expression) -> bool;
fn count<F>(&self, predicate: F) -> usize
where F: Fn(&Expression) -> bool;
fn children(&self) -> Vec<&Expression>;
fn tree_depth(&self) -> usize;
fn transform_owned<F>(self, fun: F) -> Result<Expression>
where F: Fn(Expression) -> Result<Option<Expression>>,
Self: Sized;
}Expand description
Extension trait that adds traversal and search methods to Expression.
This trait is implemented for Expression and provides a fluent API for
iterating, searching, measuring, and transforming expression trees without
needing to import the iterator types directly.
Required Methods§
Sourcefn dfs(&self) -> DfsIter<'_> ⓘ
fn dfs(&self) -> DfsIter<'_> ⓘ
Returns a depth-first (pre-order) iterator over this expression and all descendants.
The root node is yielded first, then its children are visited recursively from left to right.
Sourcefn bfs(&self) -> BfsIter<'_> ⓘ
fn bfs(&self) -> BfsIter<'_> ⓘ
Returns a breadth-first (level-order) iterator over this expression and all descendants.
All nodes at depth N are yielded before any node at depth N+1.
Sourcefn find<F>(&self, predicate: F) -> Option<&Expression>
fn find<F>(&self, predicate: F) -> Option<&Expression>
Finds the first expression matching predicate in depth-first order.
Returns None if no descendant (including this node) matches.
Sourcefn find_all<F>(&self, predicate: F) -> Vec<&Expression>
fn find_all<F>(&self, predicate: F) -> Vec<&Expression>
Collects all expressions matching predicate in depth-first order.
Returns an empty vector if no descendants match.
Sourcefn contains<F>(&self, predicate: F) -> bool
fn contains<F>(&self, predicate: F) -> bool
Returns true if this node or any descendant matches predicate.
Sourcefn count<F>(&self, predicate: F) -> usize
fn count<F>(&self, predicate: F) -> usize
Counts how many nodes (including this one) match predicate.
Sourcefn children(&self) -> Vec<&Expression>
fn children(&self) -> Vec<&Expression>
Returns direct child expressions of this node.
Collects all single-child fields and list-child fields into a flat vector of references. Leaf nodes return an empty vector.
Sourcefn tree_depth(&self) -> usize
fn tree_depth(&self) -> usize
Returns the maximum depth of the expression tree rooted at this node.
A leaf node has depth 0, a node whose deepest child is a leaf has depth 1, etc.
Sourcefn transform_owned<F>(self, fun: F) -> Result<Expression>
fn transform_owned<F>(self, fun: F) -> Result<Expression>
Transforms this expression tree bottom-up using the given function (owned variant).
Children are transformed first, then fun is called on the resulting node.
Return Ok(None) from fun to replace a node with NULL.
Return Ok(Some(expr)) to substitute the node with expr.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".