I’m using a trait for an abstract syntax tree (alas, an enum is not an option because I want plugins to be able to add node types). So far, everything has worked well, with one exception:
Problem: Due to generics, SyntaxNode isn’t object-safe anymore.
I initially used an fn type but then I can’t use closures and collect data via side effects. What is the most elegant solution or workaround in this case? Thanks!
In cases where you already have a &mut dyn FnMut(&mut dyn SyntaxNode) at hand, make sure to still call traverse_mut_dyn directly, since calling traverse_mut instead would add another layer of dynamic function calls and indirections; would be particularly bad in a (set of) recursively implemented trait impl(s) in the definition(s) of other traverse_mut_dyn methods.