macro_rules! bail_out {
($handler:expr) => { ... };
}Expand description
A convenience macro to construct a bail-out handler for the graceful bail-out path.
The handler receives a &RewritingError and a
&mut BailOut through which it can append final bytes
to the sink before the rewriter’s own raw flush.
§Example
use lol_html::{bail_out, rewrite_str, RewriteStrSettings};
use lol_html::errors::RewritingError;
use lol_html::html_content::ContentType;
let result = rewrite_str(
r#"<span>foo</span>"#,
RewriteStrSettings::new()
.append_bail_out_handler(bail_out!(|err, bail_out| {
if matches!(err, RewritingError::ContentHandlerError(_)) {
bail_out.append("<!-- bailed -->", ContentType::Html);
}
})),
)
.unwrap();
// No bail-out happened, so the handler never fired.
assert_eq!(result, "<span>foo</span>");