#[compose]Expand description
Inject a cx: &mut UiScope first parameter into the annotated function.
The attribute exists to keep infrastructure out of the signature the user reads:
ⓘ
#[compose]
fn counter_button(sig: Signal<i32>) {
ui! {
View (bg_color: ColorToken::Primary)
on Tap { sig.update(|n| *n += 1); }
{ Text($sig) }
};
}Every ui! invocation inside the function body reads cx.world_mut() /
cx.parent() implicitly; callers pass their existing cx through the
paired ui!(func(args)) form so no site ever spells out world and
parent again.
The attribute rejects three shapes at expansion time:
- non-function items — annotate a fn, or reach for
mold!(Name { ... })when you want a full widget class. async fn— cross-await UI state is a separate topic (v0.41+).- generic fn — parameter monomorphisation is deferred to a later release.
It also errors out if the user already declared a parameter named cx,
so double-injection can’t silently pass through.