Skip to main content

Flagsmith Rust SDK

The SDK client for Rust https://flagsmith.com/. Flagsmith allows you to manage feature flags and remote config across multiple projects, environments and organisations.

The source code for the client is available on Github.

The client SDK is published to Crates

Basic Usage

The SDK is initialised against a single environment within a project on https://flagsmith.com, for example the Development or Production environment. You can find your environment key in the Environment settings page.

API Key

Usage

Retrieving feature flags for your project

In your application initialise the Flagsmith client with your API key

let flagsmith = flagsmith::Client::new("<Your API Key>");

To check if a feature flag exists and is enabled:

let flagsmith = flagsmith::Client::new("<Your API Key>");
if flagsmith.feature_enabled("cart_abundant_notification_ab_test_enabled")? {
println!("Feature enabled");
}

To get the configuration value for feature flag value:

use flagsmith::{Client,Value};

let flagsmith = Client::new("<Your API Key>");

if let Some(Value::String(s)) = bt.get_value("cart_abundant_notification_ab_test")? {
println!("{}", s);
}

More examples can be found in the Tests

Override default configuration

By default, client is using default configuration. You can override configuration as follows:

let flagsmith = flagsmith::Client {
api_key: String::from("secret key"),
base_uri: String::from("https://features.on.my.own.server/api/v1/"),
};