Skip to main content

static_node

Function static_node 

Source
pub fn static_node<Msg: Clone + 'static>(
    id: u64,
    build: impl FnOnce() -> UITree<Msg>,
) -> UITree<Msg>
Expand description

Builds build() exactly once and caches the result; subsequent calls return a clone() of the cached UITree<Msg>. id must be a stable, globally unique identifier for this static subtree — the macro generates one per static node (the address of a synthesized static sentinel), never a bare counter, because a bare counter would collide across separate view! calls sharing this one cache.

Panics on the (impossible) case that id was reused with a different Msg, because the cache stores Rc<dyn Any> keyed by id and a type mismatch would mean the macro assigned the same id twice.