Rust
The Unleash Rust SDK lets you evaluate feature flags in Rust applications. It connects to Unleash or Unleash Edge to fetch flag configurations and evaluates them locally against an Unleash context.
You can use this SDK with Unleash Enterprise or Unleash Open Source.
For an overview of how Unleash SDKs work, including offline behavior, feature compatibility across SDKs, and default refresh and metrics intervals, refer to the SDK overview.
Client overview
The client is written using async rust. For communicating with the Unleash API surf or reqwest support is built in, or any async HTTP client can be provided by the user if they implement the thin trait used to abstract over the actual client.
Examples with async-std (feature ‘surf-client’) and tokio (feature ‘reqwest-client’) are in the examples/ in the source tree. See the API docs for more feature information.
To use it in a sync program, run an async executor and block_on() the relevant
calls. As the client specification requires sending background metrics to the
API, you will need to arrange to call the poll_for_updates method from a
thread as demonstrated in examples/theads.rs
The unleash defined strategies are included, to support custom strategies
use the ClientBuilder and call the strategy method to register your custom
strategy memoization function.
The crate documentation should be consulted for more detail.
Configuration
The easiest way to get started with the Client is using the ClientBuilder. A simple example is provided:
The values required for the into_client method are described as follows (in order, as seen above):
api_url- The server URL to fetch toggles from.app_name- The name of your application.instance_id- A unique ID, ideally per run. A runtime generated UUID would be a sensible choice here.authorization- An Unleash client secret, if set this will be passed as the authorization header.
While the above code shows the usage of the EnvironmentConfig, this isn’t required and is provided as a convenient way of reading a data from the system environment variables.
Note that if you do use the EnvironmentConfig as a way of accessing the system variables, you’ll need to ensure that all the environment variables marked as required in the above table are set, or a panic will be raised.
The ClientBuilder also has a few builder methods for setting properties which are assumed to have good defaults and generally do not require changing. If you do need to alter these properties you can invoke the following methods on the builder (as seen above with the interval).
Status
Core Unleash API features work, with Rust 1.60 or above. The MSRV for this project is weakly enforced: when a hard dependency raises its version, so will the minimum version tested against, but if older rust versions work for a user, that is not prevented. time in particular is known to enforce a 6-month compiler age, so regular increases with the minimum version tested against are expected.
Unimplemented Unleash specified features:
- local serialised copy of toggles to survive restarts without network traffic.