Skip to main content

Visit

Trait Visit 

Source
pub trait Visit<T> {
    // Required methods
    fn visit<'a>(&'a self) -> impl Iterator<Item = &'a T>
       where T: 'a;
    fn visit_mut<'a>(&'a mut self) -> impl Iterator<Item = &'a mut T>
       where T: 'a;

    // Provided methods
    fn visit_rec<'a, F>(&'a self, f: &mut F)
       where T: Visit<T> + 'a,
             F: FnMut(&T) { ... }
    fn visit_rec_mut<'a, F>(&'a mut self, f: &mut F)
       where T: Visit<T> + 'a,
             F: FnMut(&mut T) { ... }
}

Required Methods§

Source

fn visit<'a>(&'a self) -> impl Iterator<Item = &'a T>
where T: 'a,

Visit each child node of type T in the subtree of Self.

Implementations of Visit do not recurse past T, meaning that if you really want to visit all children of type T you would have to call <T as Visit<T>>::visit on each visited T. Alternatively, use Self::visit_rec which solves this exact problem.

Source

fn visit_mut<'a>(&'a mut self) -> impl Iterator<Item = &'a mut T>
where T: 'a,

Mutable version of Self::visit.

Provided Methods§

Source

fn visit_rec<'a, F>(&'a self, f: &mut F)
where T: Visit<T> + 'a, F: FnMut(&T),

Visit each child node of type T in the subtree of Self, recursively in depth-first order.

Due to Rust’s aliasing model, you can’t iterate mutably on a node and its children. This function allows visiting recursively by passing a closure instead.

Source

fn visit_rec_mut<'a, F>(&'a mut self, f: &mut F)
where T: Visit<T> + 'a, F: FnMut(&mut T),

Mutable version of Self::visit_rec.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§