Skip to main content

Module guard

Module guard 

Source
Expand description

The WhenActive middleware, and asking about a flag from inside a handler.

Shaped like rustlavel_rbac::Can, because it is a neighbouring conversation: that middleware decides whether this user may see a route, this one decides whether the route is there for them yet.

ⓘ
router.group("/checkout", |r| {
    r.middleware(Authenticate::from_config(&config));
    r.middleware(WhenActive::new("new-checkout"));
    r.post("", place_order);
});

router.get("/search", |req: Request| async move {
    // Or ask inside the handler, when the flag changes the page rather
    // than removing it.
    let template = if req.flag("beta-search").await? { "search.beta" } else { "search" };
    Ok(Response::html(render(template)))
});

Structs§

WhenActive
A route that is not there yet.

Traits§

FlagsExt
req.flag(...) — asking about a flag from inside a handler.