2 releases

0.1.1 Aug 8, 2024
0.1.0 Aug 8, 2024

#234 in Configuration

Download history 115/week @ 2024-08-02 93/week @ 2024-08-09 6/week @ 2024-08-16

214 downloads per month

MIT license

21KB
226 lines

ConfigCat OpenFeature Provider for Rust

Build Status crates.io docs.rs

This repository contains an OpenFeature provider that allows ConfigCat to be used with the OpenFeature Rust SDK.

Installation

Run the following Cargo command in your project directory:

cargo add configcat-openfeature-provider

Or add the following to your Cargo.toml:

[dependencies]
configcat-openfeature-provider = "0.1"

Usage

The ConfigCatProvider needs a pre-configured ConfigCat Rust SDK client:

use std::time::Duration;
use configcat::{Client, PollingMode};
use open_feature::OpenFeature;
use configcat_openfeature_provider::ConfigCatProvider;

#[tokio::main]
async fn main() {
    // Acquire an OpenFeature API instance.
    let mut api = OpenFeature::singleton_mut().await;

    // Configure the ConfigCat SDK.
    let configcat_client = Client::builder("<YOUR-CONFIGCAT-SDK-KEY>")
        .polling_mode(PollingMode::AutoPoll(Duration::from_secs(60)))
        .build()
        .unwrap();

    // Configure the provider.
    api.set_provider(ConfigCatProvider::new(configcat_client)).await;

    // Create a client.
    let client = api.create_client();

    // Evaluate a feature flag.
    let is_awesome_feature_enabled = client
        .get_bool_value("isAwesomeFeatureEnabled", None, None)
        .await
        .unwrap_or(false);
}

For more information about all the configuration options, see the Rust SDK documentation.

Example

This repository contains a simple example application that you can run with:

cargo run --example print_eval

Need help?

https://configcat.com/support

Contributing

Contributions are welcome. For more info please read the Contribution Guideline.

About ConfigCat

ConfigCat is a feature flag and configuration management service that lets you separate releases from deployments. You can turn your features ON/OFF using ConfigCat Dashboard even after they are deployed. ConfigCat lets you target specific groups of users based on region, email or any other custom user attribute.

ConfigCat is a hosted feature flag service. Manage feature toggles across frontend, backend, mobile, desktop apps. Alternative to LaunchDarkly. Management app + feature flag SDKs.

Dependencies

~9–21MB
~304K SLoC