#[actions]Expand description
Declare a module as containing form action handlers.
Action handlers are functions which handle form actions, typically over POST.
To declare a function as a handler, annotate it with the #[action] attribute.
Function parameters representing form fields should be annotated with the #[form] attribute.
§Attributes
state- The “state” used in generated handlers.axum- Integrate withaxum.handler- The name of the generated handler to be used as the POST handler. Defaults toactions_handler.
picoserve- Integrate withpicoserve.path_parameters- The types of the path parameters.handler- The name of the generated struct which implementsRequestHandlerService.
§Macro Output
The macro modifies the module, inserting the following content:
-
For each “action”, a module with the same name is generated, containing:
- A
pub structcalledFormrepresenting the form values, with the following field:action- The name of the action, to be used as the “action” attribute of the HTML form.- For each
#[form]parameter,{parameter_name}_name- The name of the form field, to be used as the “name” attribute of the HTML input.
- A
pub constcalledFORM, containing the values ofForm.
- A
-
If
axumintegration is declared:- A function which can be used as an axum
Handler, which routes the request to the appropriate#[action].
- A function which can be used as an axum
-
If
picoserveintegration is declared:- A struct which implements
RequestHandlerServiceby routing the request to the appropriate#[action].
- A struct which implements
All other content is unchanged, allowing you to mix action handlers with other items.