Struct lib_ruby_parser::traverse::visitor::Visitor[][src]

pub struct Visitor<T> where
    T: Observer
{ pub observer: T, }
Expand description

Generic visitor of Node.

It doesn’t do anything on its own, but it notifies given Observer.

struct MyObserver {
    pub numbers: Vec<nodes::Int>,
}

impl Observer for MyObserver {
    fn on_int(&mut self, node: &nodes::Int) {
        self.numbers.push(node.clone())
    }
}

let source = "2 + 3";
let mut parser = Parser::new(source.as_bytes(), ParserOptions::default());
let ast = parser.do_parse().ast.unwrap();

let observer = MyObserver { numbers: vec![] };
let visitor = Visitor { observer };

visitor.visit_root(&ast);

println!("{:?}", visitor.observer.numbers);
// => [Int { value: "2" }, Int { value: "3" }]

Fields

observer: T

Observer of the visitor, receives calls like on_int(&mut self, node: nodes::Int)

Implementations

Starts traversing on a given node

Trait Implementations

Formats the value using the given formatter. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.