macro_rules! element {
($selector:expr, $handler:expr) => { ... };
}Expand description
A convenience macro to construct a rewriting handler for elements that can be matched by the specified CSS selector.
§Example
use lol_html::{rewrite_str, element, RewriteStrSettings};
use lol_html::html_content::ContentType;
let html = rewrite_str(
r#"<span id="foo"></span>"#,
RewriteStrSettings {
element_content_handlers: vec![
element!("#foo", |el| {
el.set_inner_content("Hello!", ContentType::Text);
Ok(())
})
],
..RewriteStrSettings::new()
}
).unwrap();
assert_eq!(html, r#"<span id="foo">Hello!</span>"#);When using sendable handlers, beware that the Element type has a generic argument that controls Send compatibility.
Use send::Element or write the closure’s argument’s type as &mut Element<'_, '_, _>.
This macro can create either sendable or non-sendable handlers, but not both in a generic context.
H: HandlerTypes bound won’t work with this macro.