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>
Create a rate limiter. Starts with capacity tokens (full
bucket). refill_rate_per_sec controls the steady-state
rate; both fields must be > 0.
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.
pub fn flush(&self) -> Result<(), RateLimiterError>
pub fn flush_async(&self) -> Result<(), RateLimiterError>
Trait Implementations§
fn header(&self) -> &HandshakeHeader
fn ring(&self) -> &ObservationRing
fn make_policy(&self) -> Box<dyn Policy>
Source§fn apply_migration(&self, new_tag: u32)
fn apply_migration(&self, new_tag: u32)
Called by the sidecar when the policy returns a new strategy
tag. Default implementation: just set the tag on the header.
Primitives that need heavier migration (data-layout swap)
override this to perform the swap before (or after) updating
the tag.
Auto Trait Implementations§
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