You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It is common for the visit_* methods to return void (as opposed to in the example). In that case it is possible to factor out the
traversal code and share it between algorithms (and also to provide noop default methods). In Rust, the common way to do this
is to provide walk_* functions for each datum. For example,
I have a hard time understanding this section. I have a few questions:
What is meant by "each datum" here? I'm guessing an AST node is a datum, but just to clearify.
There is no self parameter in the example walk_expr function following the paragraph. Where would I put this function? At first I thought one would put it on "each datum", but then there is no self so yeah... it can't be a method. It could be an associated function, that might make sense I guess. Also, it does get an Expr as an argument, as a substitution for self i guess. But again just to clearify.
The first parameter visitor is typed as &mut Visitor, however because Visitor is a trait I get a compiler error saying I should use the dyn keyword. This confuses me. Maybe it's just a typo?
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
-
Regarding the visitor pattern found under Chapter 3.1.6, Section "Discussion".
I have a hard time understanding this section. I have a few questions:
self
parameter in the examplewalk_expr
function following the paragraph. Where would I put this function? At first I thought one would put it on "each datum", but then there is noself
so yeah... it can't be a method. It could be an associated function, that might make sense I guess. Also, it does get anExpr
as an argument, as a substitution forself
i guess. But again just to clearify.visitor
is typed as&mut Visitor
, however becauseVisitor
is atrait
I get a compiler error saying I should use thedyn
keyword. This confuses me. Maybe it's just a typo?Thanks!
Beta Was this translation helpful? Give feedback.
All reactions