Implement the visitor pattern with interchangable implementations for both the visit algorithm and node object traversal. It is also possible to dynamically create temporary 'virtual' nodes during traversal.
An object traversal is comprised of 3 parts:
The input to traverse, which can start at any node type. This can be an external type too, there are no required derives or trait impls.
The director navigates between node objects. It must implement Direct<N> for each node type N in the object graph, determining the sub-nodes.
The visitor performs the desired algorithm, implementing Visit<N> for each node type N in the object graph.
syn
The crate includes a low-pain replacement for syn::visit::Visit if the syn feature is enabled. Implement directed_visit::syn::visit::Full as you would syn::visit::Visit. For your director, directed_visit::syn::direct::FullDefault traverses as syn::visit does, or you can customize the behavior by implementing directed_visit::syn::direct::Full. The derive feature subset of full is not yet supported.
Limitations
Because the director can dynamically create new nodes to visit, the visitor cannot hold references to the node graph (i.e. there is no single 'ast lifetime for all nodes). For this reason there is also currently no VisitMut equivalent, because the ideal interaction between handling temporary dynamic nodes and mutating them is unclear.