Skip to main content

Crate composure_macros

Crate composure_macros 

Source
Expand description

Procedural macros for Composure, the Discord Interactions framework. Use them through composure with its macros feature, which re-exports them: composure::{app, command, group, component, modal, autocomplete, view, rsx, Choice, Modal}.

Macro
#[app]Collects Commands, Groups, handlers, Views and other Apps into the handler an Adapter serves
#[command]A Command from a function: Options from its parameters, the description from its doc comment
#[group]A Command whose subcommands are other Commands
#[autocomplete]Suggestions for an Option while the user types
#[component]Answers buttons and selects by custom_id prefix, with state in the custom_id
#[modal]Answers modal submits by custom_id prefix
#[derive(Modal)]A form shown as a modal, read back typed
#[derive(Choice)]An enum of fixed Choices
rsx!Markup for message and modal layouts
#[view]A layout rendered from Props, with inline handlers

The Composure guide explains each in depth; Views lists every rsx! tag and attribute.

Macros§

rsx
Markup for a message or modal layout, as JSX: built-in tags are Discord’s components (<Container>, <Section>, <Text>, <Thumbnail>, <Gallery>/<Item>, <File>, <Separator>, <Row>, <Button>, <StringSelect>/<Option>, <UserSelect>, …; in a <Modal>: <Label>, <TextInput>, <RadioGroup>, <CheckboxGroup>, <Checkbox>, <FileUpload>), PascalCase tags are #[view]s. Evaluates to a View, or a ModalView for a <Modal> root.

Attribute Macros§

app
Makes a unit struct an App: the Interaction Handler routing to the Commands, Groups, Component and Modal Handlers, Views and other Apps listed in handlers(..), in any mix and order.
autocomplete
Defines an Autocomplete Handler from a function taking an optional leading ctx: Ctx and what the user has typed so far as input: &str. Attach it to a string, integer, or number Option with #[option("...", autocomplete = name)].
command
Defines a Command from a function. Parameters after an optional leading ctx: Ctx become Options; the doc comment becomes the description.
component
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(..).
group
Makes a unit struct a Group that routes to its subcommands. Groups can contain Groups one level deep.
modal
Defines a Modal Handler from a function: it answers submits of modals whose custom_id starts with the prefix. After an optional leading ctx: ModalCtx comes the form (a #[derive(Modal)] type), then state carried in the custom_id. name::show(..) is the modal response that opens the form.
view
Defines a View: a layout rendered from its Props (the parameters, owned values), whose rsx!s may hold inline handlers.

Derive Macros§

Choice
Makes a fieldless enum (1-25 variants) usable as an Option restricted to its variants, and as the options of selects, radio groups and checkbox groups.
Modal
A form shown as a modal: each named field is one input inside a Label.