macro_rules! fragment {
    () => { ... };
    (move { $($input:tt)* }) => { ... };
    ({ $($input:tt)* }) => { ... };
}
Expand description

Creates a Fragment which can be inserted into a DomBuilder.

A fragment is a collection of children, you can use all of the methods in FragmentBuilder:

let x = fragment!({
    .text("foo")
    .child(html!("div", { ... }))
    .children_signal_vec(...)
});

You can then insert the fragment into a DomBuilder:

html!("div", {
    .fragment(&x)
})

The fragment is inlined, so it is exactly the same as if you had written this, there is no performance cost:

html!("div", {
    .text("foo")
    .child(html!("div", ...))
    .children_signal_vec(...)
})

The same fragment can be inserted multiple times, and it can be inserted into multiple different DomBuilder.

Fragments are very useful for passing children into another component:

Foo::render(&state.foo, fragment!({
    .text("Hello!")
}))

There are three syntaxes for fragment:

  1. fragment!() creates an empty fragment.

  2. fragment!({ ... }) creates a normal fragment.

  3. fragment!(move { ... }) creates a fragment which moves the outer variables into the fragment, just like a closure.

When returning a fragment from a function, you will usually need to use the move syntax:

fn my_fragment() -> impl Fragment {
    let x = some_string();

    fragment!(move {
        .text(&x)
    })
}