maciejhirsz / kobold

Easy declarative web interfaces.
https://docs.rs/kobold/
Mozilla Public License 2.0
385 stars 7 forks source link

`{ for<N> ... }` bounded lists #100

Closed maciejhirsz closed 2 months ago

maciejhirsz commented 2 months ago

This PR adds a new way to declare lists by adding <N> after the for keyword:

view! {
    <ol.unbounded>
    {
       // Still works as it used to!
       for (0..10).map(|n| view! { <li>{n} })
    }
    </ol>

    <ol.bounded>
    {
       // A list that's bound to max length of 10
       for<10> (0..10).map(|n| view! { <li>{n} })
    }
    </ol>
}

Unlike the default unbounded lists, bounded lists are array-backed and therefore do not cause any allocations.