A small Rust application showing how to consume the published Featurevisor Rust SDK from crates.io.
The application downloads a Featurevisor datafile, creates an SDK instance, sets a context, and evaluates one feature as a flag, variation, and string variable.
Rust 1.74 or newer.
cargo runThe application fetches this production datafile:
https://featurevisor-example-cloudflare.pages.dev/production/featurevisor-mobile.json
The important SDK usage is in src/main.rs:
use featurevisor::{context, create_featurevisor, DatafileInput, FeaturevisorOptions};
let f = create_featurevisor(FeaturevisorOptions {
datafile: Some(DatafileInput::Json(datafile)),
..Default::default()
});
f.set_context(
context! {
"userId" => "mobile-user",
"country" => "nl",
},
false,
);
let enabled = f.is_enabled("mobile_experience", None);
let variation = f.get_variation("mobile_experience", None, None);
let welcome_message = f.get_variable_string(
"mobile_experience",
"welcome_message",
None,
None,
);The featurevisor dependency comes from crates.io. It is not a local path dependency, so this project demonstrates the same setup used by a new consumer.
Learn more in the Featurevisor Rust SDK documentation.
The datafile is generated by the Featurevisor example Cloudflare project.