Skip to main content

Crate feature_flag

Crate feature_flag 

Source
Expand description

§feature-flag

Server-side feature flag evaluation for async Rust services.

§Design rules

  1. No external RNG. Sticky bucketing is a SHA-256 of (flag_id ‖ subject_id) mod 100 — deterministic, no entropy source, no rand dep.
  2. Tokio is assumed. Hot reload uses tokio::fs + an async watcher.
  3. Cheap clones. The evaluator is Arc-shaped under the hood, so handing it to many tasks is free.
  4. Snapshot for tests. Build a FlagSet in code, drop it into a FlagEvaluator, evaluate. No I/O required.

§Primitives

  • FlagSet — declarative collection of flags, deserialised from JSON.
  • Flag — one named flag with default + ordered targeting Rules.
  • Rule — a match_when Predicate plus an outcome (Variant or percentage rollout).
  • Predicate — small DSL of typed comparisons + all_of / any_of / not.
  • Subject — the entity being evaluated (id + arbitrary attributes).
  • FlagEvaluator — combines a FlagSet with a sticky-bucketing function.
  • HotReloader — watches a JSON file for changes and atomically swaps the evaluator’s FlagSet.

§Composes with

Re-exports§

pub use error::FeatureFlagError;
pub use evaluator::Evaluation;
pub use evaluator::FlagEvaluator;
pub use hot_reload::HotReloader;
pub use model::Flag;
pub use model::FlagSet;
pub use model::Rule;
pub use model::Variant;
pub use predicate::Comparison;
pub use predicate::Predicate;
pub use subject::Subject;

Modules§

error
Crate-wide error type.
evaluator
The hot path. FlagEvaluator wraps a FlagSet (behind an ArcSwap-style lock) and resolves (flag_id, subject) to a variant.
hot_reload
File-backed hot reload for FlagEvaluator.
model
Flag / Rule / FlagSet types.
predicate
Targeting predicate DSL — typed comparisons + boolean combinators.
subject
The thing flags are evaluated against.