pub trait FeatureFlagPlugin: Send + Sync {
// Required methods
fn name(&self) -> &str;
fn evaluate(
&self,
key: &str,
ctx: &FlagContext,
) -> Result<FlagValue, String>;
// Provided methods
fn evaluate_batch(
&self,
keys: &[&str],
ctx: &FlagContext,
) -> Result<HashMap<String, FlagValue>, String> { ... }
fn refresh(&self) -> Result<(), String> { ... }
fn is_healthy(&self) -> bool { ... }
}Expand description
A feature-flag provider.
The runtime holds one instance per configured backend and dispatches
flags.bool / flags.string / flags.int / flags.json host calls
through it. evaluate is the core: callers pass a flag key and a
context, the provider returns the current value.
evaluate_batch exists for the common “render-time prefetch” pattern
where a page needs to resolve a dozen flags before it can render. A
default implementation walks the keys and calls evaluate one at a
time — backends with native batch APIs (LaunchDarkly, OpenFeature’s
ProviderEvaluation list) override for efficiency.
refresh exists for backends that cache flag state (virtually all
remote providers). Local providers like @bext/flags-static override
it to re-read the config file off disk; on-change detection is out of
scope for the trait — the runtime schedules refresh itself.
Required Methods§
Sourcefn evaluate(&self, key: &str, ctx: &FlagContext) -> Result<FlagValue, String>
fn evaluate(&self, key: &str, ctx: &FlagContext) -> Result<FlagValue, String>
Evaluate a single flag. Returns the current value, or Err on
provider failure (network, malformed config, unknown value type).
A missing flag is not an error — backends return their configured default variant. This matches the OpenFeature semantic and keeps callers from having to distinguish “flag not found” from “flag is off” at call sites, which is almost never what they actually want.
Provided Methods§
Sourcefn evaluate_batch(
&self,
keys: &[&str],
ctx: &FlagContext,
) -> Result<HashMap<String, FlagValue>, String>
fn evaluate_batch( &self, keys: &[&str], ctx: &FlagContext, ) -> Result<HashMap<String, FlagValue>, String>
Evaluate several flags at once. The returned map contains one
entry per input key. Default implementation walks evaluate;
backends with native batch APIs should override.
Sourcefn refresh(&self) -> Result<(), String>
fn refresh(&self) -> Result<(), String>
Pull a fresh snapshot from the backing store. Local providers re-read the config file; remote providers fetch the latest ruleset. Default: no-op for providers that do not cache.
Sourcefn is_healthy(&self) -> bool
fn is_healthy(&self) -> bool
Health check. Default: always healthy. Remote providers should override to ping their transport.