> ## Documentation Index
> Fetch the complete documentation index at: https://confidence.spotify.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Rust

> Confidence Rust SDK for server-side feature flag evaluation.

The Confidence Rust SDK provides ultra-low latency feature flag evaluation for Rust applications using the [Confidence Resolver](https://github.com/spotify/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`:

```toml theme={null}
[dependencies]
spotify-confidence-openfeature-provider-local = "<latest>"
open-feature = "<latest>"
```

## Quickstart

```rust theme={null}
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

<CardGroup cols={2}>
  <Card title="GitHub repository" icon="github" href="https://github.com/spotify/confidence-resolver/tree/main/openfeature-provider/rust">
    Source code and examples
  </Card>

  <Card title="OpenFeature Rust SDK" icon="flag" href="https://openfeature.dev/docs/reference/technologies/server/rust">
    OpenFeature documentation
  </Card>

  <Card title="Context" icon="sliders" href="/docs/sdks/context">
    Configure evaluation context
  </Card>

  <Card title="Apply events" icon="chart-line" href="/docs/sdks/apply-event">
    Understand flag assignment tracking
  </Card>
</CardGroup>
