Rust SDK

Unpublished

Blocking client; arbitrary precision via num-bigint.

Initialize

The API key is a positional argument; new returns a Result. The client is Clone (Arc-shared).

main.rs
use counters::CountersClient;

let client = CountersClient::new(std::env::var("COUNTERS_API_KEY")?)?;

Count

add and subtract are buffered and coalesced per counter (flushed as one POST /batch); add_now/subtract_now apply immediately and return the counter. Amounts accept integers, a string, or a BigInt.

count
let reg = client.counter("registrations")?;

reg.add(1)?;         // buffered
reg.add(5)?;         // coalesced
client.flush()?;     // one POST /batch

let c = reg.add_now(1)?; // immediate
println!("{}", c.value); // "42"

Read

Read the current value, or a per-bucket time series. from/to are RFC 3339 strings; event-time writes use the separate add_now_at/subtract_now_at methods.

read
let value = reg.value()?.value;

let series = reg.series(
    SeriesParams::new("2026-01-01T00:00:00Z", "2026-01-08T00:00:00Z", "1d"),
)?;

Manage

clear resets to zero (new epoch, history retained); delete tombstones the counter; list pages the counters in the organization.

manage
reg.clear()?;
reg.delete()?;

let page = client.list(None, Some(50))?; // cursor, limit

Lifecycle

Buffered writes flush on a worker thread and at max_batch_size. Call close before the program exits so nothing is lost.

lifecycle
client.close()?; // flush + stop the worker thread

Errors

Everything returns Result with one CountersError enum: Validation (bad input), Api (non-2xx, carries status/title/problem), and Transport (network).

errors
use counters::CountersError;

match reg.add_now(1) {
    Ok(c) => println!("value = {}", c.value),
    Err(CountersError::Validation(msg)) => eprintln!("bad input: {msg}"),
    Err(CountersError::Api { status, .. }) => eprintln!("api error {status}"),
    Err(e) => eprintln!("{e}"),
}
Prefer raw HTTP? See the REST API reference. Create a key in your dashboard.