Skip to main content

controller

Attribute Macro controller 

Source
#[controller]
Expand description

Marks an impl block as a controller. Rewrites action methods into axum-compatible handlers, wiring in any filters.

Filters are declared with the #[before_action(...)] / #[after_action(...)] helper attributes on action methods; this macro parses and consumes them while expanding the impl block, so there are no standalone before_action/after_action macros to import:

#[controller]
impl PostsController {
    #[before_action(require_auth)]
    #[before_action(load_record, only = [show, edit])]
    #[after_action(log_response)]
    async fn show(ctx: &mut Context) -> Response { /* ... */ }
}

before_action filters run in declaration order before the action and may short-circuit by returning Err(response); after_action filters run after.