Trait html_page::Visitor

source ·
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§

source

fn visit_element(&mut self, _: &Element)

Visit an element.

source

fn visit_text(&mut self, _: &str)

Visit non-HTML text content.

source

fn visit_html(&mut self, _: &str)

Visit literal HTML content.

source

fn visit(&mut self, root: &Element)

Visit recursively an element and each of its children.

Implementors§