Rust SDK
A feature flag lets you choose between application behaviors without changing the deployed code. Toggly's Rust client downloads an application's definitions and evaluates flags locally using the context you provide.
Use the Rust cheat sheet (PDF) beside these guides. The Toggly Samples catalog contains complete applications and flag setup recipes for reference.
Package Architecture
| Crate | Purpose |
|---|---|
toggly | Client, configuration, evaluation, entity mapping and telemetry |
toggly-actix | Actix middleware and extractors |
toggly-axum | Axum layers, extractors and state wrapper |
toggly-axum08 | Axum 0.8 layers, extractors and state wrapper |
toggly-rocket | Rocket initialization fairing and request guard |
toggly-macros | Optional function gates and feature-key enums |
Install only the adapter used by your application.
Requirements
Use Rust 1.88 or later and a Tokio runtime. The native adapter guides declare their supported host dependencies: Actix, Axum and Rocket.
Framework compatibility
| Adapter | Declared host range | Current tested host | Required configuration |
|---|---|---|---|
toggly-axum | Axum 0.7 | Axum 0.7.9 | Register Arc<TogglyClient> as an Extension |
toggly-axum08 | Axum 0.8 | Axum 0.8.9 | Register Arc<TogglyClient> as an Extension |
toggly-actix | Actix-web 4.4 through 4.15 | Actix-web 4.15.0 | Register web::Data<TogglyClient> |
toggly-rocket | Rocket 0.5 | Rocket 0.5.1 | Attach the fairing or manage one client |
toggly-axum and toggly-axum08 are separate crates because Axum 0.7 and
0.8 use incompatible dependency types. Keep the package and import matching
your host major. The adapters intentionally map evaluation errors to false
in their convenience feature helpers; use direct client access when the host
must handle the SDK error explicitly.
Installation
For a standalone application, add these dependencies to Cargo.toml:
[dependencies]
toggly = "0.6"
tokio = { version = "1", features = ["macros", "rt-multi-thread"] }
Quick Start
Create a Toggly application, select its Production environment, and create new-dashboard with an AlwaysOn condition. Set TOGGLY_APP_KEY in your local shell to that application's SDK key. Environment names and feature keys are case-sensitive. Do not commit the key.
Put this complete example in src/main.rs, then run cargo run:
use toggly::{EvalContext, TogglyClient};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
// Prepare known targeting before the first evaluation.
// In a server, obtain these values from the authenticated request.
let context = EvalContext::builder()
.identity("user-123")
.group("beta-testers")
.build();
// Create one client for this application's lifetime.
let client = TogglyClient::builder()
.app_key(std::env::var("TOGGLY_APP_KEY")?)
.environment("Production")
.build()
.await?;
let result = client.is_enabled("new-dashboard", context).await;
// Close before propagating an evaluation error or leaving the runtime.
client.close().await;
println!("New dashboard enabled: {}", result?);
Ok(())
}
The initial request downloads shared definitions for the app and environment; it does not send the user's evaluation context. is_enabled evaluates locally. There is no separate identity-setting call to perform at startup. A missing flag returns false with the default configuration. A missing app key or failed initial definition fetch returns an initialization error; handle that error in your application's startup policy.
Change the condition to AlwaysOff, save it, and run the program again: the output becomes false. A running server receives definition updates through refresh configuration; decision caching also affects when an evaluation changes.
Features
The SDK supports asynchronous evaluation, shared clients, in-memory definition and decision caches, polling, optional live updates, built-in filters, entity context, and optional usage/business-metric telemetry. Framework helpers expose native integration points, while the application supplies authenticated claims and domain data.
Rust does not expose a variant assignment or evaluated-snapshot export/import API. A caller-supplied telemetry variant label is a correlation label, not an assignment made by the SDK.
Next Steps
- Configuration and shutdown
- Evaluation, request context and Order entities
- Actix integration, Axum integration, Rocket integration
- Macros, Caching, Testing and telemetry
- Rust Rocket SDK workshop - Run a native Rocket application with request context, Order and filter examples; its local definitions fixture works without a live Toggly application.