Rust SDK

The DeployRamp Rust SDK lets you evaluate feature flags, report errors, and manage traits from any Rust application. All functions are available at the crate root.

Installation

Add deployramp to your Cargo.toml:

[dependencies]
deployramp = "0.1"

Initialization

Initialize the SDK with your public token before evaluating any flags. Use Config::new() and optionally chain .base_url() or .traits():

use deployramp::{Config, init, flag, close};

fn main() {
    init(Config::new("pk_live_abc123")).unwrap();

    if flag("new-checkout", None) {
        // new checkout flow
    }

    close();
}

Evaluating Flags

Call flag() with the flag name to check whether a feature is enabled. Pass an optional HashMap of trait overrides:

use std::collections::HashMap;

// Simple check
if deployramp::flag("new-checkout", None) {
    // new checkout flow
}

// With trait overrides
let mut overrides = HashMap::new();
overrides.insert("plan".into(), "enterprise".into());
if deployramp::flag("new-checkout", Some(&overrides)) {
    // enterprise-only checkout flow
}

Setting Traits

Traits are key-value pairs that describe the current user or environment. They influence flag evaluation on the server:

use std::collections::HashMap;

let mut traits = HashMap::new();
traits.insert("plan".into(), "pro".into());
traits.insert("region".into(), "us-east-1".into());
deployramp::set_traits(traits);

Error Reporting

Report errors so DeployRamp can correlate them with flag rollouts and trigger automatic rollbacks when needed:

if let Err(e) = process_payment() {
    deployramp::report(
        &e.to_string(),
        None,
        Some("new-checkout"),
        None,
    );
}

Shutdown

Call close() when your application is shutting down to flush any pending events and release resources:

deployramp::close();

API Reference

FunctionParametersReturnsDescription
initconfig: ConfigResult<(), String>Initialize the SDK. Build config via Config::new("token"), optionally chain .base_url() and .traits().
flagname: &str, trait_overrides: Option<&HashMap<String, String>>boolEvaluate a feature flag, optionally with trait overrides.
set_traitstraits: HashMap<String, String>()Set traits for flag evaluation.
reporterror_msg: &str, stack: Option<&str>, flag_name: Option<&str>, trait_overrides: Option<&HashMap<String, String>>()Report an error, optionally associated with a specific flag.
closenone()Flush pending events and release resources.

We use cookies to analyze site usage and improve your experience.