Skip to main content

FlagsExt

Trait FlagsExt 

Source
pub trait FlagsExt {
    // Required methods
    fn flags(&self) -> Result<Flags>;
    fn flag_scope(&self) -> Scope;
    fn scoped_flags(&self) -> Result<ScopedFlags>;
    fn flag(&self, flag: &str) -> impl Future<Output = Result<bool>> + Send;
    fn flag_off(&self, flag: &str) -> impl Future<Output = Result<bool>> + Send;
}
Expand description

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

The companion to WhenActive, for when the flag changes the page rather than removing it: a new panel, a different template, an extra field on a form.

Every method returns Result, and that is deliberate. “I could not find out” is a third answer, distinct from on and from off, and collapsing it into false would turn a store outage into a silent, global rollback that looks exactly like the flag being off on purpose.

Required Methods§

Source

fn flags(&self) -> Result<Flags>

The registry from application state.

Source

fn flag_scope(&self) -> Scope

The scope this request is checked as.

The logged-in rustlavel_auth::Identity if there is one — attached by the auth middleware, or read from the session if only the session middleware is installed — and Scope::none otherwise. A guest is not a scope of their own: they are everybody, and giving them one would mean a percentage rollout that reshuffles on every visit.

Source

fn scoped_flags(&self) -> Result<ScopedFlags>

A ScopedFlags for this request, reusing the one WhenActive attached if there is one.

Take it once and keep it when a handler checks several flags. Calling FlagsExt::flag repeatedly on a request that did not come through WhenActive runs the resolver once per call — the memo lives in the view, and a fresh view remembers nothing.

Source

fn flag(&self, flag: &str) -> impl Future<Output = Result<bool>> + Send

Is this flag on for whoever is making this request?

Source

fn flag_off(&self, flag: &str) -> impl Future<Output = Result<bool>> + Send

The negation, for the reading that comes out shorter.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementations on Foreign Types§

Source§

impl FlagsExt for Request

Source§

fn flags(&self) -> Result<Flags>

Source§

fn flag_scope(&self) -> Scope

Source§

fn scoped_flags(&self) -> Result<ScopedFlags>

Source§

async fn flag(&self, flag: &str) -> Result<bool>

Source§

async fn flag_off(&self, flag: &str) -> Result<bool>

Implementors§