Skip to main content

streaming

Macro streaming 

Source
macro_rules! streaming {
    ($closure:expr) => { ... };
}
Expand description

A convenience macro to construct a StreamingHandler from a closure.

For use with Element::streaming_replace, etc.

The closure must be 'static (can’t capture by a temporary reference), and Send, even when using non-sendable rewriter.

use lol_html::{element, streaming, RewriteStrSettings};
use lol_html::html_content::ContentType;

RewriteStrSettings::new().append_element_content_handler(element!("div", |element| {
    element.streaming_replace(streaming!(|sink| {
        sink.write_str("…", ContentType::Html);
        sink.write_str("…", ContentType::Html);
        Ok(())
    }));
    Ok(())
}));

Note: if you get “implementation of FnOnce is not general enough” error, add explicit argument sink: &mut StreamingHandlerSink<'_> to the closure.