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 {
    element_content_handlers: vec![
        element!("div", |element| {
            element.streaming_replace(streaming!(|sink| {
                sink.write_str("…", ContentType::Html);
                sink.write_str("…", ContentType::Html);
                Ok(())
            }));
            Ok(())
        })
    ],
    ..RewriteStrSettings::default()
};

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