Skip to main content

HtmlFragment

Struct HtmlFragment 

Source
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 render and render_with_capacity
  • Used as component props with generic T: IntoHtml bounds
  • 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: F

Trait Implementations§

Source§

impl<F> IntoHtml for HtmlFragment<F>
where F: FnOnce(&mut HtmlFormatter<'_>),

Source§

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<'_>),

Source§

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.