Skip to content

Rust API

The detent crate in bindings/rust/ wraps the C++ client with cxx. It’s built when DETENT_BUILD_RUST=ON.


impl Client {
pub fn new(
defaults_path: &str,
source_path: Option<&str>,
cli_overrides: Vec<String>,
poll_interval_ms: i32,
) -> Result<Self, DetentError>;
pub fn get(
&self,
name: &str,
hash_val: Option<&str>,
switch_val: Option<&str>,
) -> Result<i64, DetentError>;
pub fn get_bool(
&self,
name: &str,
hash_val: Option<&str>,
switch_val: Option<&str>,
) -> Result<bool, DetentError>;
pub fn health(&self) -> HealthInfo;
}
let client = detent::Client::new("/etc/myapp/defaults.json", None, vec![], 200)?;
if client.get_bool("checkout:killswitch_new_path", None, None)? {
new_checkout();
}
let limit = client.get("search:max_results", None, None)?;

get reads a knob’s i64 value with the standard precedence. get_bool calls get, then returns false for 0 and true for 1; any other value is a ConversionFailed error.


pub struct HealthInfo {
pub initialized: bool,
pub source_connected: bool,
pub accepted_version: u64,
pub staleness_seconds: f64,
pub knobs: usize,
pub cli_overrides: usize,
}

pub struct DetentError(pub String);

Implements std::error::Error and Display; the message starts with the error category, e.g. MissingKnob: ....