pub trait Walker {
// Required method
fn walk<V>(&self, visitor: &mut V)
where V: AstVisitor;
}Expand description
The Walker implements the traversal of the AST nodes and Ast-related objects (e.g. CompilationUnit).
The walk method is called on the object to visit its children.
If the object passed to a AstVisitor’s visit method implements the Walker trait,
a call to the it’s walk function continues the visiting process on its children.
Spliting the traversal logic into a separate trait allows to call the default traversal logic
from the visitor while overriding the visitor’s visit method for specific nodes.
§Example
use plc_ast::ast::AstNode;
use plc_ast::visitor::Walker;
use plc_ast::visitor::AstVisitor;
struct MyAssignment {
left: AstNode,
right: AstNode,
}
impl Walker for MyAssignment {
fn walk<V>(&self, visitor: &mut V)
where
V: AstVisitor,
{
visitor.visit(&self.right);
visitor.visit(&self.left);
}
}Required Methods§
fn walk<V>(&self, visitor: &mut V)where
V: AstVisitor,
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.