Skip to main content

Crate larust_pennant

Crate larust_pennant 

Source
Expand description

Laravel’s laravel/pennant - feature flags, narrowed to its core: persisted, scope-aware boolean flags, with no process-wide resolver registry.

No Feature::define(...) registry, deliberately. Real Pennant lets an app register a default-value closure once (typically in a service provider), and Feature::active(...) calls it lazily on first check per scope, persisting the result. A process-wide OnceLock<HashMap<String, BoxedResolver>> could reproduce that here, but this framework has already rejected that exact shape once - larust_queue::JobRegistry’s own doc comment is explicit that its handler map is “not a process-wide static… built fresh by whatever calls work()”, specifically because only one thing in one process ever needs it. A feature flag’s default has the same shape: decided by the one call site that cares, not a registry every part of the app must agree to populate before anything can check a flag. active takes its default as a plain argument instead - the caller supplies “what if nothing’s been decided yet” right where it’s checked, same as any other Option-shaped default would be.

Boolean-only, not Pennant’s richer non-boolean “value” flags (Feature::value('purchase-button', fn () => ...) returning a string/ array) - deliberately out of scope for this version: the vast majority of real Pennant usage is the boolean on/off case this crate covers, and a typed, non-boolean value store is a genuinely different, larger feature (what type? how is it validated? how does a caller declare the type it expects back?) worth its own design, not bolted on speculatively here.

Storage is unconditionally SQL (feature_flags, this crate’s own table - the same “owns a small table” shape larust-sanctum/ larust-permissions/larust-notifications/larust-cache each already have), not Pennant’s own pluggable array/database driver split: an in-memory driver would silently lose every flag on restart, which defeats the entire point of a persisted rollout decision - not a real choice worth offering.

Re-exported through larust_support::pennant (see crates/ larust-support/src/lib.rs) so generated apps depend only on larust-support, never on this crate directly - the same wiring every other optional Tier-1 shim crate already uses.

§Deliberately out of scope for this version

  • No @feature/@endfeature Blade directive. Unlike @can/ @role (gated by larust-permissions), larust-view’s own directive set is a fixed list hardcoded in its parser, not a pluggable registry an optional crate can extend - adding one is a real, separate change to a core crate, not something this crate can do on its own. active is still callable directly from any controller/view-context-building code in the meantime, same as Laravel’s own Feature::active(...) is usable outside Blade too.
  • No pennant:purge-equivalent “purge everything” operation. purge removes one named flag across every scope (the safe, common “retire this flag” case); clearing the entire table in one call is a sharper footgun with no real use case this crate has seen requested yet.
  • No rich/non-boolean values - see this doc comment’s own opening for why.

Functions§

activate
Persists name as active for scope - every later active call for this exact pair returns true until deactivate/forget. Laravel’s Feature::activate('x').
active
Whether name is active for scope (None for the unscoped, global case - see [normalize_scope]’s own doc comment). Returns default when nothing has been decided yet for this exact (name, scope) pair - the caller’s own fallback, not a registered resolver (see this crate’s own doc comment for why). Laravel’s Feature::for($user)->active('x')/ plain Feature::active('x').
deactivate
Persists name as inactive for scope - every later active call for this exact pair returns false until activate/forget. Laravel’s Feature::deactivate('x').
forget
Removes any stored decision for (name, scope) - a later active call for this exact pair falls back to its own default argument again, as if nothing had ever been decided. Laravel’s Feature::forget('x').
purge
Removes every stored decision for name, across every scope - for retiring a flag entirely once a rollout is finished, rather than forgetting one scope at a time. Laravel’s Feature::purge('x') (this crate has no equivalent of purging every flag in one call - see this module’s own doc comment for why).