Skip to main content

Visitor

Trait Visitor 

Source
pub trait Visitor {
    type Break;

    // Provided methods
    fn enter(&mut self, this: &dyn Any) -> ControlFlow<Self::Break> { ... }
    fn leave(&mut self, this: &dyn Any) -> ControlFlow<Self::Break> { ... }
}
Expand description

A visitor that can be used to traverse a data structure.

Implement this trait to define custom logic that executes when Traversable items are visited. You can implement enter and leave methods to perform actions before and after processing a node, respectively.

For an example of implementing Visitor, see the FileCounter struct in the crate-level documentation.

You can also use visitor to create a visitor from closures.

Required Associated Types§

Source

type Break

The type that can be used to break traversal early.

Provided Methods§

Source

fn enter(&mut self, this: &dyn Any) -> ControlFlow<Self::Break>

Called when the visitor is entering a node.

Default implementation does nothing and continues traversal.

Source

fn leave(&mut self, this: &dyn Any) -> ControlFlow<Self::Break>

Called when the visitor is leaving a node.

Default implementation does nothing and continues traversal.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§

Source§

impl<T, B, F1, F2> Visitor for FnVisitor<T, B, F1, F2>
where T: Any, F1: FnMut(&T) -> ControlFlow<B>, F2: FnMut(&T) -> ControlFlow<B>,

Source§

type Break = B

Source§

impl<V1, V2> Visitor for Chain<V1, V2>
where V1: Visitor, V2: Visitor<Break = V1::Break>,

Source§

type Break = <V1 as Visitor>::Break