Skip to content

Instantly share code, notes, and snippets.

@nikomatsakis
Created April 16, 2013 15:25
Show Gist options
  • Save nikomatsakis/5396859 to your computer and use it in GitHub Desktop.
Save nikomatsakis/5396859 to your computer and use it in GitHub Desktop.
////////////////////
// in visit.rs:
trait Visitor {
fn visit_item(&mut self, item: @ast::item) { ... }
fn visit_expr(&mut self, expr: @ast::expr) { visit_expr(self, expr); }
...
}
// default implementations:
fn visit_expr<V:Visitor>(&mut V, expr: @ast::Expr) {...}
////////////////////
// in somewhere else:
pub struct MyContext {
...
}
impl Visitor for MyContext {
fn visit_expr(&mut self, expr: @ast::expr) {
visit::visit_expr(self, expr); // visit sub-expressions
match expr.node {
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment