pub trait Visitor {
// Provided methods
fn visit_element(&mut self, _: &Element) { ... }
fn visit_text(&mut self, _: &str) { ... }
fn visit_html(&mut self, _: &str) { ... }
fn visit(&mut self, root: &Element) { ... }
}
Expand description
A read-only visitor for an HTML element.
Implementing this trait allows “visiting” element and all of its
children. The provided Visitor::visit
method visits the
element first, and then each of its children in order, and
recursively visits the children of each child.
#[derive(Default)]
struct Collector {
tags: Vec<Tag>,
text: String,
}
impl Visitor for Collector {
fn visit_element(&mut self, e: &Element) {
self.tags.push(e.tag());
}
fn visit_text(&mut self, s: &str) {
self.text.push_str(s);
}
}
Provided Methods§
sourcefn visit_element(&mut self, _: &Element)
fn visit_element(&mut self, _: &Element)
Visit an element.
sourcefn visit_text(&mut self, _: &str)
fn visit_text(&mut self, _: &str)
Visit non-HTML text content.
sourcefn visit_html(&mut self, _: &str)
fn visit_html(&mut self, _: &str)
Visit literal HTML content.