plait/fragment.rs
1use crate::HtmlFormatter;
2
3/// A wrapper type for HTML rendering closures returned by the [`html!`](crate::html) macro.
4///
5/// `HtmlFragment` wraps a closure that writes HTML to an [`HtmlFormatter`]. This type implements both
6/// [`IntoHtml`](crate::IntoHtml) and [`IntoHtmlRaw`](crate::IntoHtmlRaw), allowing fragments to be:
7///
8/// - Passed to [`render`](crate::render) and [`render_with_capacity`](crate::render_with_capacity)
9/// - Used as component props with generic `T: IntoHtml` bounds
10/// - Stored in variables and composed together
11/// - Embedded in other [`html!`](crate::html) fragments via `(expr)` or `#(expr)` syntax
12///
13/// You typically don't create `HtmlFragment` directly - it's returned by the [`html!`](crate::html) macro.
14///
15/// # Examples
16///
17/// ```rust
18/// use plait::{IntoHtml, html, render};
19///
20/// // Store a fragment in a variable
21/// let header = html! { h1 { "Welcome" } };
22///
23/// // Use it in another fragment
24/// let page = render(html! {
25/// div {
26/// (header)
27/// p { "Content" }
28/// }
29/// });
30///
31/// assert_eq!(page, "<div><h1>Welcome</h1><p>Content</p></div>");
32/// ```
33pub struct HtmlFragment<F>(pub F)
34where
35 F: FnOnce(&mut HtmlFormatter<'_>);