pub struct HtmlFragment<F>(pub F)
where
F: FnOnce(&mut HtmlFormatter<'_>);Expand description
A wrapper type for HTML rendering closures returned by the html! macro.
HtmlFragment wraps a closure that writes HTML to an HtmlFormatter. This type implements both
IntoHtml and IntoHtmlRaw, allowing fragments to be:
- Passed to
renderandrender_with_capacity - Used as component props with generic
T: IntoHtmlbounds - Stored in variables and composed together
- Embedded in other
html!fragments via(expr)or#(expr)syntax
You typically don’t create HtmlFragment directly - it’s returned by the html! macro.
§Examples
use plait::{IntoHtml, html, render};
// Store a fragment in a variable
let header = html! { h1 { "Welcome" } };
// Use it in another fragment
let page = render(html! {
div {
(header)
p { "Content" }
}
});
assert_eq!(page, "<div><h1>Welcome</h1><p>Content</p></div>");Tuple Fields§
§0: FTrait Implementations§
Source§impl<F> IntoHtml for HtmlFragment<F>where
F: FnOnce(&mut HtmlFormatter<'_>),
impl<F> IntoHtml for HtmlFragment<F>where
F: FnOnce(&mut HtmlFormatter<'_>),
Source§fn render_to(self, f: &mut HtmlFormatter<'_>)
fn render_to(self, f: &mut HtmlFormatter<'_>)
Renders this value to the given HTML formatter with escaping.
Source§impl<F> IntoHtmlRaw for HtmlFragment<F>where
F: FnOnce(&mut HtmlFormatter<'_>),
impl<F> IntoHtmlRaw for HtmlFragment<F>where
F: FnOnce(&mut HtmlFormatter<'_>),
Source§fn render_raw_to(self, f: &mut HtmlFormatter<'_>)
fn render_raw_to(self, f: &mut HtmlFormatter<'_>)
Renders this value to the given HTML formatter without escaping.
Auto Trait Implementations§
impl<F> Freeze for HtmlFragment<F>where
F: Freeze,
impl<F> RefUnwindSafe for HtmlFragment<F>where
F: RefUnwindSafe,
impl<F> Send for HtmlFragment<F>where
F: Send,
impl<F> Sync for HtmlFragment<F>where
F: Sync,
impl<F> Unpin for HtmlFragment<F>where
F: Unpin,
impl<F> UnwindSafe for HtmlFragment<F>where
F: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more