Trait Visitable

Source
pub trait Visitable<'tree> {
    // Required methods
    fn children(&self) -> Vec<Node<'tree>>;
    fn node(&self) -> Node<'tree>;

    // Provided method
    fn visit<VisitorT>(
        &self,
        visitor: VisitorT,
    ) -> Result<bool, VisitorT::Error>
       where VisitorT: Visitor<'tree> { ... }
}
Expand description

Walk-specific trait adding the ability to traverse the KCL AST.

This trait is implemented on Node to handle the fairly tricky bit of recursing into the AST in a single place, as well as helpers for traversing the tree. for callers to use.

Required Methods§

Source

fn children(&self) -> Vec<Node<'tree>>

Return a Vec<Node> for all direct children of this AST node. This should only contain direct descendants.

Source

fn node(&self) -> Node<'tree>

Return self as a Node. Generally speaking, the Visitable trait is only going to be implemented on Node, so this is purely used by helpers that are generic over a Visitable and want to deref back into a Node.

Provided Methods§

Source

fn visit<VisitorT>(&self, visitor: VisitorT) -> Result<bool, VisitorT::Error>
where VisitorT: Visitor<'tree>,

Call the provided [Visitor] in order to Visit self. This will only be called on self – the [Visitor] is responsible for recursing into any children, if desired.

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§

Source§

impl<'tree> Visitable<'tree> for Node<'tree>