Skip to main content

Rust Quickstart

The Eppo Rust SDK enables feature flags and experiments in your Rust applications with only a few lines of code.

The SDK handles all the complexity of feature flag evaluation and experiment assignment locally in your application, with no network calls required after initial setup.

Installation​

First, add the SDK as a dependency using Cargo:

cargo add eppo

Feature Flags​

Feature flags are a way to toggle features on and off without needing to deploy code.

Initialize the SDK​

Create an SDK key if you don't already have one.

let mut client = eppo::ClientConfig::from_api_key("<YOUR_API_KEY>")
.to_client();

let poller_thread = client.start_poller_thread().unwrap();

// Optional: wait 5 seconds for the poller to fetch configuration before serving assignments.
let _ = poller_thread.wait_for_configuration_timeout(Duration::from_secs(5));

Assign a variant​

Once initialized, you can use the client to make assignments. Each assignment requires:

  • Flag Key: Identifies which set of configuration rules to use
  • Subject Key: A unique identifier for the subject (usually a user ID)
  • Subject Attributes: Optional key-value pairs containing additional information used for rule evaluation
let variation = client
.get_string_assignment(
"<FLAG_KEY>",
"<SUBJECT_KEY>",
<SUBJECT_ATTRIBUTES>,
)
.inspect_err(|err| eprintln!("error assigning a flag: {:?}", err))
.unwrap_or_default()
.unwrap_or("<DEFAULT_VALUE>".to_owned());

if variation == "fast_checkout" {
// Handle fast checkout
} else {
// Handle other variations
}

Assignment Types​

The SDK provides different assignment functions based on the type of value you need:

FunctionReturn Type
get_string_assignment()Str
get_boolean_assignment()bool
get_json_assignment()serde_json::Value
get_integer_assignment()i64
get_numeric_assignment()f64

Experiments​

For experiments, you'll need to implement assignment logging to track how users interact with different variations.

use eppo::AssignmentLogger;

struct MyAssignmentLogger;

impl AssignmentLogger for MyAssignmentLogger {
fn log_assignment(&self, assignment: AssignmentEvent) {
println!("{:?}", assignment);
}
}

let mut client = ClientConfig::from_api_key("<YOUR_API_KEY>")
.assignment_logger(MyAssignmentLogger)
.to_client();

let poller_thread = client.start_poller_thread();
note

In a production application, you would want to replace the println!() statement with an actual logging system.

Next Steps​

Now that you've seen how to make assignments with the Eppo Rust SDK, we strongly recommend familiarizing yourself with the following topics: