pub trait Transform {
// Required method
fn transform(&mut self, expr: Expr) -> Expr
where Self: Sized;
}Expand description
A trait for transforming AST expressions.
This trait allows you to recursively transform expressions by visiting
all sub-expressions. The transform method is called recursively on all
sub-expressions, allowing you to transform the AST in a composable way.
§Example
use filter_expr::{Expr, Transform};
struct MyTransformer;
impl Transform for MyTransformer {
fn transform(&mut self, expr: Expr) -> Expr {
// Transform the expression before recursing
match expr {
Expr::Field(name) if name == "old_name" => {
Expr::Field("new_name".to_string())
}
other => other,
}
}
}