Skip to main content

ElementContentHandler

Trait ElementContentHandler 

pub trait ElementContentHandler {
    // Required method
    fn handle_element(
        &mut self,
        selector: usize,
        element: &mut Element<'_>,
    ) -> Result<(), Box<dyn Error + Send + Sync>>;
}
Available on crate features html and http only.
Expand description

Handles matched elements during a rewrite.

Implement this on your own type — that type holds any state the handler accumulates, mutated through &mut self. selector is the index (in registration order) of the selector that matched element.

For one-off rewrites, the closure-based ElementContentHandlers builder implements this trait for you.

Required Methods§

fn handle_element( &mut self, selector: usize, element: &mut Element<'_>, ) -> Result<(), Box<dyn Error + Send + Sync>>

Handles a matched element.

§Errors

Returning an error aborts the rewrite and surfaces the error from HtmlRewriter::write / end.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§