Skip to main content

StateStore

Trait StateStore 

Source
pub trait StateStore: Send + Sync {
    // Required method
    fn try_acquire(
        &self,
        key: &str,
        cost: f64,
        params: BucketParams,
    ) -> Acquired;
}
Expand description

The extension seam onto which the enterprise multi-node store plugs in (Redis/shared store — BOUNDARY §2.1/§4). Public ABI, frozen before the first release (§5).

The contract is a single atomic operation, not a get/update pair: refilling a bucket and consuming from it MUST be indivisible w.r.t. concurrent callers, otherwise two nodes (or threads) read the same level and both allow — a cluster-wide over-allow (TOCTOU). In-memory enforces this under one lock; a Redis impl uses a single server-side script. Time and memory-bounding are the store’s concern (in-memory owns a Clock and a tracked-key cap; Redis uses its own server time and TTL), so they never appear in the ABI.

Required Methods§

Source

fn try_acquire(&self, key: &str, cost: f64, params: BucketParams) -> Acquired

Atomically refill key’s bucket for the elapsed time, then try to take cost tokens. Allowed iff at least cost tokens are available.

Dyn Compatibility§

This trait is dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety".

Implementors§