pub trait VisitChildren<T> {
    // Required methods
    fn visit_children<F>(&self, f: F)
       where F: FnMut(&T);
    fn visit_mut_children<F>(&mut self, f: F)
       where F: FnMut(&mut T);
    fn try_visit_children<F, E>(&self, f: F) -> Result<(), E>
       where F: FnMut(&T) -> Result<(), E>,
             E: From<RecursionLimitError>;
    fn try_visit_mut_children<F, E>(&mut self, f: F) -> Result<(), E>
       where F: FnMut(&mut T) -> Result<(), E>,
             E: From<RecursionLimitError>;
}
Expand description

A trait for types that can visit their direct children of type T.

Implementing VisitChildren<Self> automatically also implements the Visit trait, which enables recursive traversal.

Note that care needs to be taken when implementing this trait for mutually recursive types (such as a type A where A has children of type B and vice versa). More specifically, at the moment it is not possible to implement versions of VisitChildren<A> for A such that A considers as its children all A-nodes occurring at leaf positions of B-children and vice versa for VisitChildren<B> for B. Doing this will result in recusion limit violations as indicated in the accompanying test_recursive_types_b test.

Required Methods§

source

fn visit_children<F>(&self, f: F)
where F: FnMut(&T),

Apply an infallible immutable function f to each direct child.

source

fn visit_mut_children<F>(&mut self, f: F)
where F: FnMut(&mut T),

Apply an infallible mutable function f to each direct child.

source

fn try_visit_children<F, E>(&self, f: F) -> Result<(), E>
where F: FnMut(&T) -> Result<(), E>, E: From<RecursionLimitError>,

Apply a fallible immutable function f to each direct child.

For mutually recursive implementations (say consisting of two types A and B), recursing through B in order to find all A-children of a node of type A might cause lead to a RecursionLimitError, hence the bound on E.

source

fn try_visit_mut_children<F, E>(&mut self, f: F) -> Result<(), E>
where F: FnMut(&mut T) -> Result<(), E>, E: From<RecursionLimitError>,

Apply a fallible mutable function f to each direct child.

For mutually recursive implementations (say consisting of two types A and B), recursing through B in order to find all A-children of a node of type A might cause lead to a RecursionLimitError, hence the bound on E.

Object Safety§

This trait is not object safe.

Implementors§