Trait IntoHtml

Source
pub trait IntoHtml {
    // Required method
    fn into_html(self) -> impl IntoHtml;

    // Provided methods
    fn escape_and_write(self, buf: &mut Buffer)
       where Self: Sized { ... }
    fn size_hint(&self) -> usize { ... }
    fn into_string(self) -> String
       where Self: Sized { ... }
}
Expand description

A type that can be represented as HTML.

Required Methods§

Source

fn into_html(self) -> impl IntoHtml

Converts this value into HTML by producing a type that implements IntoHtml.

This method enables composition of HTML structures by delegating rendering to the returned value. Use it to build nested HTML elements, combine components, or leverage existing IntoHtml implementations.

§Examples

Compose nested HTML elements using macros:

struct Article {
    title: String,
    content: String,
    author: String,
}

impl IntoHtml for Article {
    fn into_html(self) -> impl IntoHtml {
        article!(
            h1!(self.title),
            p!(class = "content", self.content),
            footer!("Written by ", self.author)
        )
    }
}

Chain multiple implementations through delegation:

struct ArticlePage {
    title: String,
    articles: Vec<Article>,
}

impl IntoHtml for ArticlePage {
    fn into_html(self) -> impl IntoHtml {
        html!(head!(title!(self.title)), body!(self.articles))
    }
}

For “leaf” types (elements that render directly without children, like primitive values), always return self to avoid infinite recursion:

struct TextNode(String);

impl IntoHtml for TextNode {
    fn into_html(self) -> impl IntoHtml {
        // Leaf type returns itself to terminate the rendering chain
        self
    }

    fn escape_and_write(self, buf: &mut Buffer) {
        escape_into(buf, &self.0);
    }

    fn size_hint(&self) -> usize {
        self.0.len()
    }
}

Provided Methods§

Source

fn escape_and_write(self, buf: &mut Buffer)
where Self: Sized,

Writes the HTML into the provided String.

Source

fn size_hint(&self) -> usize

Source

fn into_string(self) -> String
where Self: Sized,

Allocates a new String containing the HTML.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl IntoHtml for &str

Source§

fn into_html(self) -> impl IntoHtml

Source§

fn escape_and_write(self, buf: &mut Buffer)

Source§

fn size_hint(&self) -> usize

Source§

impl IntoHtml for &String

Source§

fn into_html(self) -> impl IntoHtml

Source§

fn size_hint(&self) -> usize

Source§

impl IntoHtml for bool

Source§

fn into_html(self) -> impl IntoHtml

Source§

fn size_hint(&self) -> usize

Source§

impl IntoHtml for char

Source§

fn into_html(self) -> impl IntoHtml

Source§

fn escape_and_write(self, buf: &mut Buffer)

Source§

fn size_hint(&self) -> usize

Source§

impl IntoHtml for f32

Source§

fn into_html(self) -> impl IntoHtml

Source§

fn escape_and_write(self, buf: &mut Buffer)

Source§

impl IntoHtml for f64

Source§

fn into_html(self) -> impl IntoHtml

Source§

fn escape_and_write(self, buf: &mut Buffer)

Source§

impl IntoHtml for i8

Source§

fn into_html(self) -> impl IntoHtml

Source§

fn escape_and_write(self, buf: &mut Buffer)

Source§

impl IntoHtml for i16

Source§

fn into_html(self) -> impl IntoHtml

Source§

fn escape_and_write(self, buf: &mut Buffer)

Source§

impl IntoHtml for i32

Source§

fn into_html(self) -> impl IntoHtml

Source§

fn escape_and_write(self, buf: &mut Buffer)

Source§

impl IntoHtml for i64

Source§

fn into_html(self) -> impl IntoHtml

Source§

fn escape_and_write(self, buf: &mut Buffer)

Source§

impl IntoHtml for i128

Source§

fn into_html(self) -> impl IntoHtml

Source§

fn escape_and_write(self, buf: &mut Buffer)

Source§

impl IntoHtml for isize

Source§

fn into_html(self) -> impl IntoHtml

Source§

fn escape_and_write(self, buf: &mut Buffer)

Source§

impl IntoHtml for u8

Source§

fn into_html(self) -> impl IntoHtml

Source§

fn escape_and_write(self, buf: &mut Buffer)

Source§

impl IntoHtml for u16

Source§

fn into_html(self) -> impl IntoHtml

Source§

fn escape_and_write(self, buf: &mut Buffer)

Source§

impl IntoHtml for u32

Source§

fn into_html(self) -> impl IntoHtml

Source§

fn escape_and_write(self, buf: &mut Buffer)

Source§

impl IntoHtml for u64

Source§

fn into_html(self) -> impl IntoHtml

Source§

fn escape_and_write(self, buf: &mut Buffer)

Source§

impl IntoHtml for u128

Source§

fn into_html(self) -> impl IntoHtml

Source§

fn escape_and_write(self, buf: &mut Buffer)

Source§

impl IntoHtml for ()

Source§

fn into_html(self) -> impl IntoHtml

Source§

fn escape_and_write(self, _: &mut Buffer)

Source§

impl IntoHtml for usize

Source§

fn into_html(self) -> impl IntoHtml

Source§

fn escape_and_write(self, buf: &mut Buffer)

Source§

impl IntoHtml for String

Source§

fn into_html(self) -> impl IntoHtml

Source§

fn escape_and_write(self, buf: &mut Buffer)

Source§

fn size_hint(&self) -> usize

Source§

impl<A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z> IntoHtml for (A, B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z)

Source§

fn into_html(self) -> impl IntoHtml

Source§

fn escape_and_write(self, buf: &mut Buffer)

Source§

fn size_hint(&self) -> usize

Source§

impl<B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z> IntoHtml for (B, C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z)

Source§

fn into_html(self) -> impl IntoHtml

Source§

fn escape_and_write(self, buf: &mut Buffer)

Source§

fn size_hint(&self) -> usize

Source§

impl<B: IntoHtml, I: ExactSizeIterator, F> IntoHtml for Map<I, F>
where F: FnMut(I::Item) -> B,

Source§

fn into_html(self) -> impl IntoHtml

Source§

fn escape_and_write(self, buf: &mut Buffer)

Source§

impl<C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z> IntoHtml for (C, D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z)

Source§

fn into_html(self) -> impl IntoHtml

Source§

fn escape_and_write(self, buf: &mut Buffer)

Source§

fn size_hint(&self) -> usize

Source§

impl<D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z> IntoHtml for (D, E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z)

Source§

fn into_html(self) -> impl IntoHtml

Source§

fn escape_and_write(self, buf: &mut Buffer)

Source§

fn size_hint(&self) -> usize

Source§

impl<E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z> IntoHtml for (E, F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z)

Source§

fn into_html(self) -> impl IntoHtml

Source§

fn escape_and_write(self, buf: &mut Buffer)

Source§

fn size_hint(&self) -> usize

Source§

impl<F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z> IntoHtml for (F, G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z)

Source§

fn into_html(self) -> impl IntoHtml

Source§

fn escape_and_write(self, buf: &mut Buffer)

Source§

fn size_hint(&self) -> usize

Source§

impl<G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z> IntoHtml for (G, H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z)

Source§

fn into_html(self) -> impl IntoHtml

Source§

fn escape_and_write(self, buf: &mut Buffer)

Source§

fn size_hint(&self) -> usize

Source§

impl<H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z> IntoHtml for (H, I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z)

Source§

fn into_html(self) -> impl IntoHtml

Source§

fn escape_and_write(self, buf: &mut Buffer)

Source§

fn size_hint(&self) -> usize

Source§

impl<I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z> IntoHtml for (I, J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z)

Source§

fn into_html(self) -> impl IntoHtml

Source§

fn escape_and_write(self, buf: &mut Buffer)

Source§

fn size_hint(&self) -> usize

Source§

impl<J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z> IntoHtml for (J, K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z)

Source§

fn into_html(self) -> impl IntoHtml

Source§

fn escape_and_write(self, buf: &mut Buffer)

Source§

fn size_hint(&self) -> usize

Source§

impl<K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z> IntoHtml for (K, L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z)

Source§

fn into_html(self) -> impl IntoHtml

Source§

fn escape_and_write(self, buf: &mut Buffer)

Source§

fn size_hint(&self) -> usize

Source§

impl<L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z> IntoHtml for (L, M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z)
where L: IntoHtml, M: IntoHtml, N: IntoHtml, O: IntoHtml, P: IntoHtml, Q: IntoHtml, R: IntoHtml, S: IntoHtml, T: IntoHtml, U: IntoHtml, V: IntoHtml, W: IntoHtml, X: IntoHtml, Y: IntoHtml, Z: IntoHtml,

Source§

fn into_html(self) -> impl IntoHtml

Source§

fn escape_and_write(self, buf: &mut Buffer)

Source§

fn size_hint(&self) -> usize

Source§

impl<M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z> IntoHtml for (M, N, O, P, Q, R, S, T, U, V, W, X, Y, Z)
where M: IntoHtml, N: IntoHtml, O: IntoHtml, P: IntoHtml, Q: IntoHtml, R: IntoHtml, S: IntoHtml, T: IntoHtml, U: IntoHtml, V: IntoHtml, W: IntoHtml, X: IntoHtml, Y: IntoHtml, Z: IntoHtml,

Source§

fn into_html(self) -> impl IntoHtml

Source§

fn escape_and_write(self, buf: &mut Buffer)

Source§

fn size_hint(&self) -> usize

Source§

impl<N, O, P, Q, R, S, T, U, V, W, X, Y, Z> IntoHtml for (N, O, P, Q, R, S, T, U, V, W, X, Y, Z)
where N: IntoHtml, O: IntoHtml, P: IntoHtml, Q: IntoHtml, R: IntoHtml, S: IntoHtml, T: IntoHtml, U: IntoHtml, V: IntoHtml, W: IntoHtml, X: IntoHtml, Y: IntoHtml, Z: IntoHtml,

Source§

fn into_html(self) -> impl IntoHtml

Source§

fn escape_and_write(self, buf: &mut Buffer)

Source§

fn size_hint(&self) -> usize

Source§

impl<O, P, Q, R, S, T, U, V, W, X, Y, Z> IntoHtml for (O, P, Q, R, S, T, U, V, W, X, Y, Z)
where O: IntoHtml, P: IntoHtml, Q: IntoHtml, R: IntoHtml, S: IntoHtml, T: IntoHtml, U: IntoHtml, V: IntoHtml, W: IntoHtml, X: IntoHtml, Y: IntoHtml, Z: IntoHtml,

Source§

fn into_html(self) -> impl IntoHtml

Source§

fn escape_and_write(self, buf: &mut Buffer)

Source§

fn size_hint(&self) -> usize

Source§

impl<P, Q, R, S, T, U, V, W, X, Y, Z> IntoHtml for (P, Q, R, S, T, U, V, W, X, Y, Z)
where P: IntoHtml, Q: IntoHtml, R: IntoHtml, S: IntoHtml, T: IntoHtml, U: IntoHtml, V: IntoHtml, W: IntoHtml, X: IntoHtml, Y: IntoHtml, Z: IntoHtml,

Source§

fn into_html(self) -> impl IntoHtml

Source§

fn escape_and_write(self, buf: &mut Buffer)

Source§

fn size_hint(&self) -> usize

Source§

impl<Q, R, S, T, U, V, W, X, Y, Z> IntoHtml for (Q, R, S, T, U, V, W, X, Y, Z)
where Q: IntoHtml, R: IntoHtml, S: IntoHtml, T: IntoHtml, U: IntoHtml, V: IntoHtml, W: IntoHtml, X: IntoHtml, Y: IntoHtml, Z: IntoHtml,

Source§

fn into_html(self) -> impl IntoHtml

Source§

fn escape_and_write(self, buf: &mut Buffer)

Source§

fn size_hint(&self) -> usize

Source§

impl<R, S, T, U, V, W, X, Y, Z> IntoHtml for (R, S, T, U, V, W, X, Y, Z)
where R: IntoHtml, S: IntoHtml, T: IntoHtml, U: IntoHtml, V: IntoHtml, W: IntoHtml, X: IntoHtml, Y: IntoHtml, Z: IntoHtml,

Source§

fn into_html(self) -> impl IntoHtml

Source§

fn escape_and_write(self, buf: &mut Buffer)

Source§

fn size_hint(&self) -> usize

Source§

impl<S, T, U, V, W, X, Y, Z> IntoHtml for (S, T, U, V, W, X, Y, Z)
where S: IntoHtml, T: IntoHtml, U: IntoHtml, V: IntoHtml, W: IntoHtml, X: IntoHtml, Y: IntoHtml, Z: IntoHtml,

Source§

fn into_html(self) -> impl IntoHtml

Source§

fn escape_and_write(self, buf: &mut Buffer)

Source§

fn size_hint(&self) -> usize

Source§

impl<T, U, V, W, X, Y, Z> IntoHtml for (T, U, V, W, X, Y, Z)
where T: IntoHtml, U: IntoHtml, V: IntoHtml, W: IntoHtml, X: IntoHtml, Y: IntoHtml, Z: IntoHtml,

Source§

fn into_html(self) -> impl IntoHtml

Source§

fn escape_and_write(self, buf: &mut Buffer)

Source§

fn size_hint(&self) -> usize

Source§

impl<T: IntoHtml> IntoHtml for Option<T>

Source§

fn into_html(self) -> impl IntoHtml

Source§

fn escape_and_write(self, buf: &mut Buffer)

Source§

fn size_hint(&self) -> usize

Source§

impl<T: IntoHtml> IntoHtml for Vec<T>

Source§

fn into_html(self) -> impl IntoHtml

Source§

fn escape_and_write(self, buf: &mut Buffer)

Source§

fn size_hint(&self) -> usize

Source§

impl<T: IntoHtml, const N: usize> IntoHtml for [T; N]

Source§

fn into_html(self) -> impl IntoHtml

Source§

fn escape_and_write(self, buf: &mut Buffer)

Source§

fn size_hint(&self) -> usize

Source§

impl<U, V, W, X, Y, Z> IntoHtml for (U, V, W, X, Y, Z)
where U: IntoHtml, V: IntoHtml, W: IntoHtml, X: IntoHtml, Y: IntoHtml, Z: IntoHtml,

Source§

fn into_html(self) -> impl IntoHtml

Source§

fn escape_and_write(self, buf: &mut Buffer)

Source§

fn size_hint(&self) -> usize

Source§

impl<V, W, X, Y, Z> IntoHtml for (V, W, X, Y, Z)
where V: IntoHtml, W: IntoHtml, X: IntoHtml, Y: IntoHtml, Z: IntoHtml,

Source§

fn into_html(self) -> impl IntoHtml

Source§

fn escape_and_write(self, buf: &mut Buffer)

Source§

fn size_hint(&self) -> usize

Source§

impl<W, X, Y, Z> IntoHtml for (W, X, Y, Z)
where W: IntoHtml, X: IntoHtml, Y: IntoHtml, Z: IntoHtml,

Source§

fn into_html(self) -> impl IntoHtml

Source§

fn escape_and_write(self, buf: &mut Buffer)

Source§

fn size_hint(&self) -> usize

Source§

impl<X, Y, Z> IntoHtml for (X, Y, Z)
where X: IntoHtml, Y: IntoHtml, Z: IntoHtml,

Source§

fn into_html(self) -> impl IntoHtml

Source§

fn escape_and_write(self, buf: &mut Buffer)

Source§

fn size_hint(&self) -> usize

Source§

impl<Y, Z> IntoHtml for (Y, Z)
where Y: IntoHtml, Z: IntoHtml,

Source§

fn into_html(self) -> impl IntoHtml

Source§

fn escape_and_write(self, buf: &mut Buffer)

Source§

fn size_hint(&self) -> usize

Source§

impl<Z> IntoHtml for (Z,)
where Z: IntoHtml,

Source§

fn into_html(self) -> impl IntoHtml

Source§

fn escape_and_write(self, buf: &mut Buffer)

Source§

fn size_hint(&self) -> usize

Implementors§

Source§

impl IntoHtml for PreEscaped<&str>

Source§

impl IntoHtml for PreEscaped<char>

Source§

impl IntoHtml for PreEscaped<String>

Source§

impl<A, B> IntoHtml for Either<A, B>
where A: IntoHtml, B: IntoHtml,

Source§

impl<A, B, C> IntoHtml for Either3<A, B, C>
where A: IntoHtml, B: IntoHtml, C: IntoHtml,

Source§

impl<A, B, C, D> IntoHtml for Either4<A, B, C, D>
where A: IntoHtml, B: IntoHtml, C: IntoHtml, D: IntoHtml,

Source§

impl<A, B, C, D, E> IntoHtml for Either5<A, B, C, D, E>
where A: IntoHtml, B: IntoHtml, C: IntoHtml, D: IntoHtml, E: IntoHtml,

Source§

impl<A, B, C, D, E, F> IntoHtml for Either6<A, B, C, D, E, F>
where A: IntoHtml, B: IntoHtml, C: IntoHtml, D: IntoHtml, E: IntoHtml, F: IntoHtml,

Source§

impl<A, B, C, D, E, F, G> IntoHtml for Either7<A, B, C, D, E, F, G>
where A: IntoHtml, B: IntoHtml, C: IntoHtml, D: IntoHtml, E: IntoHtml, F: IntoHtml, G: IntoHtml,

Source§

impl<A, B, C, D, E, F, G, H> IntoHtml for Either8<A, B, C, D, E, F, G, H>
where A: IntoHtml, B: IntoHtml, C: IntoHtml, D: IntoHtml, E: IntoHtml, F: IntoHtml, G: IntoHtml, H: IntoHtml,

Source§

impl<A, B, C, D, E, F, G, H, I> IntoHtml for Either9<A, B, C, D, E, F, G, H, I>
where A: IntoHtml, B: IntoHtml, C: IntoHtml, D: IntoHtml, E: IntoHtml, F: IntoHtml, G: IntoHtml, H: IntoHtml, I: IntoHtml,

Source§

impl<F: FnOnce(&mut Buffer)> IntoHtml for F