Attribute Macro actions

Source
#[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 with axum.
    • handler - The name of the generated handler to be used as the POST handler. Defaults to actions_handler.
  • picoserve - Integrate with picoserve.
    • path_parameters - The types of the path parameters.
    • handler - The name of the generated struct which implements RequestHandlerService.

§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 struct called Form representing 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 const called FORM, containing the values of Form.
  • If axum integration is declared:

    • A function which can be used as an axum Handler, which routes the request to the appropriate #[action].
  • If picoserve integration is declared:

All other content is unchanged, allowing you to mix action handlers with other items.