feature-flag 0.1.0

Server-side feature flag evaluation for async Rust: targeting rules, sticky percentage rollouts, hot reload, zero RNG.
Documentation
//! `cargo run --example evaluate`
//!
//! Loads `examples/flagset.json`, hands it to a [`FlagEvaluator`], and
//! evaluates a handful of subjects so you can see targeting + rollout in
//! action. No network, no clock — just a deterministic walk through the DSL.

use feature_flag::{FlagEvaluator, FlagSet, Subject};

fn main() -> Result<(), Box<dyn std::error::Error>> {
    let raw = std::fs::read_to_string(concat!(
        env!("CARGO_MANIFEST_DIR"),
        "/examples/flagset.json"
    ))?;
    let evaluator = FlagEvaluator::new(FlagSet::from_json(&raw)?);

    let subjects = [
        Subject::new("alice")
            .with_attr("country", "US")
            .with_attr("email", "alice@example.com"),
        Subject::new("bob")
            .with_attr("country", "DE")
            .with_attr("email", "bob@example.com"),
        Subject::new("carla")
            .with_attr("country", "US")
            .with_attr("email", "carla@kineticgain.com"),
    ];

    for s in &subjects {
        let r = evaluator.evaluate("new-checkout-flow", s)?;
        println!(
            "subject={:<8} country={:<3} -> {:?} (rule={:?}, reason={})",
            s.id,
            s.attr("country").and_then(|v| v.as_str()).unwrap_or("?"),
            r.variant,
            r.matched_rule_id.as_deref().unwrap_or("-"),
            r.reason
        );
    }

    Ok(())
}