Skip to main content

component

Attribute Macro component 

Source
#[component]
Available on crate feature macros only.
Expand description

Answers a component by custom_id prefix. See Components and modals. Defines a Component Handler from a function: it answers components whose custom_id starts with the prefix. Parameters after an optional leading ctx: ComponentCtx are state carried in the custom_id (owned, serde-serializable), built with the generated name::custom_id(..).

ⓘ
#[component("vote")]
fn vote(ctx: ComponentCtx, poll: u32, up: bool) -> Update<String> { ... }

// In a Command's response:
Component::new_button(ButtonStyle::Success, Some("Up".into()), None,
    Some(vote::custom_id(poll, true)?), None, None)

The return value answers like a Command’s: a new message by default, Update(..) to edit the message the component is on, ctx.defer_update(..) to do that later. List the handler in an #[app].