Skip to main content

Visit

Trait Visit 

Source
pub trait Visit {
    // Required methods
    fn visit_post<F>(&self, f: &mut F)
       where F: FnMut(&Self);
    fn visit_mut_post<F>(&mut self, f: &mut F)
       where F: FnMut(&mut Self);
    fn try_visit_post<F, E>(&self, f: &mut F) -> Result<(), E>
       where F: FnMut(&Self) -> Result<(), E>;
    fn try_visit_mut_post<F, E>(&mut self, f: &mut F) -> Result<(), E>
       where F: FnMut(&mut Self) -> Result<(), E>;
    fn visit_pre<F>(&self, f: &mut F)
       where F: FnMut(&Self);
    fn visit_pre_with_context<Context, AccFun, Visitor>(
        &self,
        init: Context,
        acc_fun: &mut AccFun,
        visitor: &mut Visitor,
    )
       where Context: Clone,
             AccFun: FnMut(Context, &Self) -> Context,
             Visitor: FnMut(&Context, &Self);
    fn visit_mut_pre<F>(&mut self, f: &mut F)
       where F: FnMut(&mut Self);
    fn try_visit_pre<F, E>(&self, f: &mut F) -> Result<(), E>
       where F: FnMut(&Self) -> Result<(), E>;
    fn try_visit_mut_pre<F, E>(&mut self, f: &mut F) -> Result<(), E>
       where F: FnMut(&mut Self) -> Result<(), E>;
    fn visit_pre_post<F1, F2>(&self, pre: &mut F1, post: &mut F2)
       where F1: FnMut(&Self) -> Option<Vec<&Self>>,
             F2: FnMut(&Self);
    fn visit_mut_pre_post<F1, F2>(&mut self, pre: &mut F1, post: &mut F2)
       where F1: FnMut(&mut Self) -> Option<Vec<&mut Self>>,
             F2: FnMut(&mut Self);
}
Expand description

A trait for types that can recursively visit their children of the same type.

This trait is automatically implemented for all implementors of VisitChildren.

All methods provided by this trait are iterative.

NB that any visitor with mutable post-traversal uses unsafe code. It is critical that VisitChildren::children_mut be written using safe code, i.e., no aliasing of children or access to parents.

Required Methods§

Source

fn visit_post<F>(&self, f: &mut F)
where F: FnMut(&Self),

Post-order immutable infallible visitor for self.

Source

fn visit_mut_post<F>(&mut self, f: &mut F)
where F: FnMut(&mut Self),

Post-order mutable infallible visitor for self.

Source

fn try_visit_post<F, E>(&self, f: &mut F) -> Result<(), E>
where F: FnMut(&Self) -> Result<(), E>,

Post-order immutable fallible visitor for self.

Source

fn try_visit_mut_post<F, E>(&mut self, f: &mut F) -> Result<(), E>
where F: FnMut(&mut Self) -> Result<(), E>,

Post-order mutable fallible visitor for self.

Source

fn visit_pre<F>(&self, f: &mut F)
where F: FnMut(&Self),

Pre-order immutable infallible visitor for self.

Source

fn visit_pre_with_context<Context, AccFun, Visitor>( &self, init: Context, acc_fun: &mut AccFun, visitor: &mut Visitor, )
where Context: Clone, AccFun: FnMut(Context, &Self) -> Context, Visitor: FnMut(&Context, &Self),

Pre-order immutable infallible visitor for self, which also accumulates context information along the path from the root to the current node’s parent. acc_fun is a similar closure as in fold. The accumulated context is passed to the visitor, along with the current node.

For example, one can use this on a MirScalarExpr to tell the visitor whether the current subexpression has a negation somewhere above it.

When using it on a MirRelationExpr, one has to be mindful that Let bindings are not followed, i.e., the context won’t include what happens with a Let binding in some other MirRelationExpr where the binding occurs in a Get.

Source

fn visit_mut_pre<F>(&mut self, f: &mut F)
where F: FnMut(&mut Self),

Pre-order mutable infallible visitor for self.

Source

fn try_visit_pre<F, E>(&self, f: &mut F) -> Result<(), E>
where F: FnMut(&Self) -> Result<(), E>,

Pre-order immutable fallible visitor for self.

Source

fn try_visit_mut_pre<F, E>(&mut self, f: &mut F) -> Result<(), E>
where F: FnMut(&mut Self) -> Result<(), E>,

Pre-order mutable fallible visitor for self.

Source

fn visit_pre_post<F1, F2>(&self, pre: &mut F1, post: &mut F2)
where F1: FnMut(&Self) -> Option<Vec<&Self>>, F2: FnMut(&Self),

A generalization of Visit::visit_pre and Visit::visit_post.

The function pre runs on self before it runs on any of the children. The function post runs on children first before the parent.

Optionally, pre can return which children, if any, should be visited (default is to visit all children).

Source

fn visit_mut_pre_post<F1, F2>(&mut self, pre: &mut F1, post: &mut F2)
where F1: FnMut(&mut Self) -> Option<Vec<&mut Self>>, F2: FnMut(&mut Self),

A generalization of Visit::visit_mut_pre and Visit::visit_mut_post.

The function pre runs on self before it runs on any of the children. The function post runs on children first before the parent.

Optionally, pre can return which children, if any, should be visited (default is to visit all children).

It is important for safety that pre is (a) safe code and (b) returns children only.

Dyn Compatibility§

This trait is not dyn compatible.

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

Implementors§

Source§

impl<T: VisitChildren<T>> Visit for T