pub trait AstVisitable: Any {
// Required methods
fn drive<V: VisitAst>(&self, v: &mut V) -> ControlFlow<V::Break>;
fn drive_mut<V: VisitAstMut>(&mut self, v: &mut V) -> ControlFlow<V::Break>;
// Provided methods
fn name(&self) -> &'static str { ... }
fn dyn_visit<T: AstVisitable>(&self, f: impl FnMut(&T)) { ... }
fn dyn_visit_mut<T: AstVisitable>(&mut self, f: impl FnMut(&mut T)) { ... }
}
Expand description
An overrideable visitor trait that can be used to conveniently traverse the whole contents of an item. This is useful when e.g. dealing with types, which show up pretty much everywhere in the ast.
This defines three traits:
AstVisitable
is a trait implemented by all the types listed below; it has adrive[_mut]
method that takes aVisitAst[Mut]
visitor and calls its methods on all the relevant subvalues ofself
encountered.VisitAst[Mut]
is a (pair of) visitor trait(s) that can be implemented by visitors. To define a visitor, implementVisitAst[Mut]
and override the methods you need.
This trait has a drive[_mut]
method that knows how to drive a VisitAst[Mut]
visitor. This
trait is implemented for all the listed types. If listed as override
, the corresponding
visitor trait has an overrideable method to visit this type. If listed as drive
, the type
will only be visited by recursing into its contents.
Morally this represents the predicate for<V: VisitAst[Mut]> Self: Drive[Mut]<AstVisitableWrapper<V>>
Required Methods§
sourcefn drive<V: VisitAst>(&self, v: &mut V) -> ControlFlow<V::Break>
fn drive<V: VisitAst>(&self, v: &mut V) -> ControlFlow<V::Break>
Recursively visit this type with the provided visitor. This calls the visitor’s visit_$any
method if it exists, otherwise visit_inner
.
sourcefn drive_mut<V: VisitAstMut>(&mut self, v: &mut V) -> ControlFlow<V::Break>
fn drive_mut<V: VisitAstMut>(&mut self, v: &mut V) -> ControlFlow<V::Break>
Recursively visit this type with the provided visitor. This calls the visitor’s visit_$any
method if it exists, otherwise visit_inner
.
Provided Methods§
sourcefn dyn_visit<T: AstVisitable>(&self, f: impl FnMut(&T))
fn dyn_visit<T: AstVisitable>(&self, f: impl FnMut(&T))
Visit all occurrences of that type inside self
, in pre-order traversal.
sourcefn dyn_visit_mut<T: AstVisitable>(&mut self, f: impl FnMut(&mut T))
fn dyn_visit_mut<T: AstVisitable>(&mut self, f: impl FnMut(&mut T))
Visit all occurrences of that type inside self
, in pre-order traversal.
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.
Implementations on Foreign Types§
source§impl<A: AstVisitable, B: AstVisitable> AstVisitable for Result<A, B>
impl<A: AstVisitable, B: AstVisitable> AstVisitable for Result<A, B>
fn drive<V: VisitAst>(&self, v: &mut V) -> ControlFlow<V::Break>
fn drive_mut<V: VisitAstMut>(&mut self, v: &mut V) -> ControlFlow<V::Break>
source§impl<A: AstVisitable, B: AstVisitable> AstVisitable for (A, B)
impl<A: AstVisitable, B: AstVisitable> AstVisitable for (A, B)
fn drive<V: VisitAst>(&self, v: &mut V) -> ControlFlow<V::Break>
fn drive_mut<V: VisitAstMut>(&mut self, v: &mut V) -> ControlFlow<V::Break>
source§impl<K: Any, T: AstVisitable> AstVisitable for HashMap<K, T>
impl<K: Any, T: AstVisitable> AstVisitable for HashMap<K, T>
Manual impl that only visits the values