Skip to main content

SharedRateLimiter

Struct SharedRateLimiter 

Source
pub struct SharedRateLimiter { /* private fields */ }

Implementations§

Source§

impl SharedRateLimiter

Source

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.

Source

pub fn open( path: impl AsRef<Path>, capacity: u32, refill_rate_per_sec: u32, ) -> Result<Self, RateLimiterError>

Source

pub fn capacity(&self) -> u32

Source

pub fn refill_rate_per_sec(&self) -> u32

Source

pub fn available(&self) -> u32

Read current available tokens (does NOT mutate state). Returns the count after accounting for refill since the last update.

Source

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.

Source

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.

Source

pub fn reset(&self)

Reset tokens to full capacity. Useful for tests / admin recovery. Not concurrency-coordinated; expect transient races with concurrent acquires.

Source

pub fn flush(&self) -> Result<(), RateLimiterError>

Source

pub fn flush_async(&self) -> Result<(), RateLimiterError>

Trait Implementations§

Source§

impl AdaptiveInstance for SharedRateLimiter

Source§

fn header(&self) -> &HandshakeHeader

Source§

fn ring(&self) -> &ObservationRing

Source§

fn make_policy(&self) -> Box<dyn Policy>

Source§

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.
Source§

impl Send for SharedRateLimiter

Source§

impl Sync for SharedRateLimiter

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.