Expand description
Owned AST transformation via the FoldOwned trait.
FoldOwned is the transformation counterpart of super::visitor::OwnedVisitor.
Where OwnedVisitor reads nodes in place, FoldOwned rebuilds them — reading
from an input node (borrowed) and returning a new owned value. Override only the
node types you want to change; all others are rebuilt identically by the default
implementations (equivalent to Clone).
§Example
use php_ast::owned::fold::{FoldOwned, fold_owned_expr};
use php_ast::owned::{Expr, ExprKind};
struct NegateInts;
impl FoldOwned for NegateInts {
fn fold_expr(&mut self, expr: &Expr) -> Expr {
if let ExprKind::Int(n) = &expr.kind {
return Expr { kind: ExprKind::Int(-n), span: expr.span };
}
fold_owned_expr(self, expr)
}
}Traits§
- Fold
Owned - Trait for transforming owned PHP AST nodes.