pub struct InMemoryStateStore { /* private fields */ }Expand description
In-memory token-bucket StateStore: the OPEN single-node implementation. The
refill-then-consume critical section is a short, synchronous map update (never
held across .await), so std::Mutex is the right choice.
Implementations§
Source§impl InMemoryStateStore
impl InMemoryStateStore
pub fn new() -> Self
Sourcepub fn with_clock(clock: Arc<dyn Clock>) -> Self
pub fn with_clock(clock: Arc<dyn Clock>) -> Self
Construct with a custom clock (deterministic tests). The clock lives on the store — time is part of how state advances, so it belongs with atomicity.
pub fn with_clock_and_cap( clock: Arc<dyn Clock>, max_tracked_keys: usize, ) -> Self
Sourcepub fn tracked_keys(&self) -> usize
pub fn tracked_keys(&self) -> usize
Number of currently tracked keys (tests/metrics). Concrete-only: a count is
cheap here but meaningless/expensive for a distributed store, so it is not
on the StateStore trait.
Trait Implementations§
Source§impl Default for InMemoryStateStore
impl Default for InMemoryStateStore
Source§impl StateStore for InMemoryStateStore
impl StateStore for InMemoryStateStore
Source§fn try_acquire(&self, key: &str, cost: f64, params: BucketParams) -> Acquired
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.Auto Trait Implementations§
impl !Freeze for InMemoryStateStore
impl !RefUnwindSafe for InMemoryStateStore
impl !UnwindSafe for InMemoryStateStore
impl Send for InMemoryStateStore
impl Sync for InMemoryStateStore
impl Unpin for InMemoryStateStore
impl UnsafeUnpin for InMemoryStateStore
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more