Skip to main content
The Confidence Rust SDK provides ultra-low latency feature flag evaluation for Rust applications using the Confidence Resolver—a native Rust resolver with async/await support built on Tokio.

Features

  • Local evaluation: Flag rules evaluate on your infrastructure in microseconds
  • OpenFeature compatible: Standard feature flag API through OpenFeature provider
  • Background sync: Flag rules and logging sync with Confidence in the background
  • High reliability: No network dependency at evaluation time

Installation

Add these dependencies to your Cargo.toml:
[dependencies]
spotify-confidence-openfeature-provider-local = "0.1.0"
open-feature = "0.2.7"

Quickstart

use open_feature::{EvaluationContext, OpenFeature};
use spotify_confidence_openfeature_provider_local::{ConfidenceProvider, ProviderOptions};

#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
    // Create provider options with your client secret
    let options = ProviderOptions::new("your-client-secret");

    // Create the Confidence provider
    let provider = ConfidenceProvider::new(options)?;

    // Set the provider on the OpenFeature singleton
    OpenFeature::singleton_mut()
        .await
        .set_provider(provider)
        .await;

    // Create an OpenFeature client
    let client = OpenFeature::singleton().await.create_client();

    // Create evaluation context with user attributes for targeting
    let context = EvaluationContext::default()
        .with_targeting_key("user-123")
        .with_custom_field("country", "US")
        .with_custom_field("plan", "premium");

    // Evaluate a boolean flag
    let enabled = client
        .get_bool_value("my-feature-flag.enabled", Some(&context), None)
        .await
        .unwrap_or(false);

    println!("Flag value: {}", enabled);

    Ok(())
}

Resources