pub struct SharedRateLimiter { /* private fields */ }Implementations§
Sourcepub fn create(
path: impl AsRef<Path>,
capacity: u32,
refill_rate_per_sec: u32,
) -> Result<Self, RateLimiterError>
pub fn create( path: impl AsRef<Path>, capacity: u32, refill_rate_per_sec: u32, ) -> Result<Self, RateLimiterError>
Obtain the limiter at path, initializing a full bucket if the
path does not yet exist and attaching to it if it does.
Attaching leaves the live token count in place; a region built
with a different capacity or refill rate is a LayoutMismatch.
refill_rate_per_sec controls the steady-state rate; both
fields must be > 0. reset refills a live
bucket in place.
pub fn open( path: impl AsRef<Path>, capacity: u32, refill_rate_per_sec: u32, ) -> Result<Self, RateLimiterError>
pub fn capacity(&self) -> u32
pub fn refill_rate_per_sec(&self) -> u32
Sourcepub fn available(&self) -> u32
pub fn available(&self) -> u32
Read current available tokens (does NOT mutate state). Returns the count after accounting for refill since the last update.
Sourcepub fn try_acquire(&self, n: u32) -> Result<(), RateLimiterError>
pub fn try_acquire(&self, n: u32) -> Result<(), RateLimiterError>
Non-blocking acquire. Atomically refills and deducts n
tokens. Returns Err(InsufficientTokens) immediately if
fewer than n tokens are available after refill.
Sourcepub fn acquire_or_wait(
&self,
n: u32,
timeout: Duration,
) -> Result<(), RateLimiterError>
pub fn acquire_or_wait( &self, n: u32, timeout: Duration, ) -> Result<(), RateLimiterError>
Blocking acquire with deadline. Spins with backoff until enough tokens are available OR the deadline passes.
Sourcepub fn reset(&self)
pub fn reset(&self)
Reset tokens to full capacity. Useful for tests / admin recovery. Not concurrency-coordinated; expect transient races with concurrent acquires.