Skip to main content

render_with_capacity

Function render_with_capacity 

Source
pub fn render_with_capacity(
    capacity: usize,
    content: impl FnOnce(&mut HtmlFormatter<'_>),
) -> Html
Expand description

Renders HTML content with a pre-allocated buffer capacity.

This function is similar to render, but pre-allocates the internal string buffer with the specified capacity. Use this when you know the approximate size of the output to avoid reallocations and improve performance.

ยงExamples

use plait::{html, render_with_capacity};

let html = render_with_capacity(1024, html! {
    div(class: "card") {
        h1 { "Title" }
        p { "Content goes here..." }
    }
});

assert_eq!(html, "<div class=\"card\"><h1>Title</h1><p>Content goes here...</p></div>");