Skip to main content

ExpressionWalk

Trait ExpressionWalk 

Source
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§

Source

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.

Source

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.

Source

fn find<F>(&self, predicate: F) -> Option<&Expression>
where F: Fn(&Expression) -> bool,

Finds the first expression matching predicate in depth-first order.

Returns None if no descendant (including this node) matches.

Source

fn find_all<F>(&self, predicate: F) -> Vec<&Expression>
where F: Fn(&Expression) -> bool,

Collects all expressions matching predicate in depth-first order.

Returns an empty vector if no descendants match.

Source

fn contains<F>(&self, predicate: F) -> bool
where F: Fn(&Expression) -> bool,

Returns true if this node or any descendant matches predicate.

Source

fn count<F>(&self, predicate: F) -> usize
where F: Fn(&Expression) -> bool,

Counts how many nodes (including this one) match predicate.

Source

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.

Source

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.

Source

fn transform_owned<F>(self, fun: F) -> Result<Expression>
where F: Fn(Expression) -> Result<Option<Expression>>, Self: Sized,

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", so this trait is not object safe.

Implementors§