Expand description
§wabot-macros
Procedural macros that give wabot-rust a developer experience close to the TypeScript decorator syntax of wabot-ts. Each macro maps to a decorator family in the original framework — see the docstring on each one for the TS analogue.
The macros emit code that depends on wabot-core. Re-exports flow
through the wabot crate so users only need use wabot::prelude::*.
Attribute Macros§
- action
@action('name')— marker on a method inside a#[ui_controller]impl block. BecomesPOST <controller>/_action/<name>returning JSON; the name defaults to the method name.- chat_
controller @chatController()— apply to animpl Controllerblock. Walks every method; methods carrying a channel marker (#[cmd], future#[telegram]/#[socket], …) are wired into a per-channel dispatch closure, and aSelf::register_channels(&Container, Arc<ChatResolver>)function is emitted that hands each channel its dispatch vialisten.- cmd
@cmd()— marks a method inside a#[chat_controller]impl block as the handler for the CLI (CmdChannel) channel. Inert outside a#[chat_controller]impl block.- command
@command('name')— apply to a command-payload struct. BakesSelf::COMMAND_NAME = "name"and animpl CommandDataso the typedrun_command/schedule_commandhelpers can find the name. The struct must also deriveSerialize + Deserialize.- command_
handler @commandHandler({ command, ...options })— apply to a handler struct. EmitsSelf::__handler_entry(&Container) -> CommandHandlerEntryso the runtime can dispatch byCOMMAND_NAME. The handler must implementasync fn handle(&self, cmd: MyCommand) -> Result<(), E: Display>on a separate inherent impl, and the struct itself must be#[injectable].- cron_
command @cronCommand({ name, cron })— apply to a command struct that’s fired periodically. BakesCOMMAND_NAME+CRON_SCHEDULE.- cron_
handler @cronHandler({ ...config })— apply to a handler struct. EmitsSelf::__cron_entry(&Container) -> CronHandlerEntry. The handler must implementasync fn handle(&self) -> Result<(), E: Display>(cron handlers carry no arguments) and the struct must be#[injectable].- delete
@onDelete(...)— seeget.- description
@description("...")— attaches a human-readable description to a field or method. On struct fields it is consumed by#[derive(Validate)]and folded into [PropertyInfo::description]. On methods it is consumed by mindset macros (later phase). Used standalone, the attribute is a no-op so it never appears as “unknown attribute”.- get
@onGet(...)— marks a method inside a#[rest_controller]impl block as an HTTP GET endpoint. Inert when used outside such a block.- head
#[head("…")]— the headers a GET would answer with, and no body.- injectable
@injectable()— emits aSelf::inject(&Container) -> Arc<Self>constructor that resolves eachArc<T>field from the container and fills the rest fromDefault. Does not auto-register; pair with#[singleton]or callcontainer.register_*manually.- max_
body #[max_body(N)]— how many bytes this endpoint buffers before refusing the request. Defaults toDEFAULT_MAX_BODY(1 MiB), which is generous for a REST payload and mean for a file upload.- middleware
@middleware(MyMiddleware)— attaches a middleware to the next endpoint method. Multiple#[middleware(...)]attributes stack; they run in source order before the handler. Inert outside a#[rest_controller]impl block.- mindset_
lang - Deprecated alias of
tool_lang. - mindset_
module - Deprecated alias of
tools, from when tool sets were a mindset-only concept. - mindset_
tool - Deprecated alias of
tool. - on_
socket_ event #[on_socket_event("name")]— marker on one method inside a#[socket_controller]impl block. Inert outside such a block.- patch
#[patch("…")]— a partial update. Seeget.- post
@onPost(...)— seeget.- put
@onPut(...)— seeget.- raw
#[raw]— take theRequestand return theResponseuntouched.- rest_
controller @restController('/path')— apply to animpl Controllerblock. The macro walks every method, finds the#[get]/#[post]/#[put]/#[delete]/#[middleware]attributes, and emits aSelf::register_routes(&Container, axum::Router) -> axum::Routerfunction that adds every endpoint nested under the controller’s base path.- singleton
@singleton()— like#[injectable], but additionally registers the type as a singleton viainventory. Equivalent to writingcontainer.register_singleton_factory::<Self, _>(|c| Self::inject(c))at framework startup, except the registration is collected at compile time so a freshContainer::new()already knows about it.- socket
@socket()— marks a method as the handler for the Socket.IO (SocketChannel) channel. Namespace + bind address come from the runtime-registeredSocketChannelConfigsingleton. Inert outside a#[chat_controller]impl block.- socket_
controller @socketController('/ns')— apply to animpl MyControllerblock. Walks every method, finds those carrying#[on_socket_event("name")], and emitsSelf::register_socket_handlers(&Container, &SocketIo).- telegram
@telegram()— marks a method as the handler for the Telegram (TelegramChannel) channel. The bot token is supplied at runtime via a registeredArc<TelegramChannelConfig>singleton, not as an attribute argument. Inert outside a#[chat_controller]impl block.- tool
#[tool("description")]— marker on one method inside a#[tools]impl block. Inert outside such a block — the enclosing macro reads it and strips it.- tool_
lang #[tool_lang("english")]— per-method language override, when one tool’s description is written in a different language from the rest of its set. Inert outside a#[tools]impl block.- tools
@tools()— apply to animpl MyToolsblock. Walks every method, finds those carrying#[tool("description")], and emits aSelf::register_tools(&Container) -> Vec<ToolDefinition>helper. The struct must be#[injectable](or#[singleton]) so dispatch can resolve it from the container.- ui_
controller @uiController({ path, app, layout })— apply to the controller’simplblock. Walks every method, interprets#[view],#[action]and#[middleware], and emitsSelf::register_ui_routes.- view
@view('/path')— marker on a method inside a#[ui_controller]impl block. The method takes&selfplus at most one typed request and returnsUiResult<ViewBody>(orUiResult<ViewOutcome>to redirect).
Derive Macros§
- Validate
#[derive(Validate)]— generates aValidateimpl that owns aModelInfodescribing the struct and avalidate()that runs every declared constraint against an instance.