Skip to main content

FixedWindowLimiter

Struct FixedWindowLimiter 

Source
pub struct FixedWindowLimiter { /* private fields */ }
Expand description

Lock-free atomic fixed-window rate limiter with an embedded monotonic clock.

Implementations§

Source§

impl FixedWindowLimiter

Core lock-free operations for FixedWindowLimiter.

Source

pub fn new(config: FixedWindowConfig) -> Self

Creates a new FixedWindowLimiter from a validated FixedWindowConfig.

§Arguments
  • FixedWindowConfig - Validated fixed-window configuration.
Source

pub fn with_clock(config: FixedWindowConfig, clock: MonotonicClock) -> Self

Creates a new FixedWindowLimiter anchored at a caller-supplied MonotonicClock.

§Arguments
  • FixedWindowConfig - Validated fixed-window configuration.
  • MonotonicClock - Monotonic clock origin.
Source

pub fn get_config(&self) -> &FixedWindowConfig

Returns the fixed-window configuration.

§Arguments
  • &Self - The limiter instance.
§Returns
  • &FixedWindowConfig - Reference to the configuration.
Source

pub fn get_clock(&self) -> &MonotonicClock

Returns the embedded monotonic clock.

§Arguments
  • &Self - The limiter instance.
§Returns
  • &MonotonicClock - Reference to the clock.
Source

pub fn check(&self) -> RateLimitDecision

Checks and consumes 1 unit using the embedded monotonic clock.

§Arguments
  • &Self - The limiter instance.
§Returns
  • RateLimitDecision - Admission decision and nanosecond timings.
Source

pub fn check_n(&self, cost: u64) -> RateLimitDecision

Checks and consumes cost units using the embedded monotonic clock.

§Arguments
  • &Self - The limiter instance.
  • u64 - Number of quota units to consume.
§Returns
  • RateLimitDecision - Admission decision and nanosecond timings.
Source

pub fn check_at_ns(&self, now_ns: u64) -> RateLimitDecision

Checks and consumes 1 unit at an explicit monotonic timestamp in nanoseconds.

§Arguments
  • &Self - The limiter instance.
  • u64 - Monotonic timestamp in nanoseconds.
§Returns
  • RateLimitDecision - Admission decision and nanosecond timings.
Source

pub fn check_n_at_ns(&self, now_ns: u64, cost: u64) -> RateLimitDecision

Checks and consumes cost units at an explicit monotonic timestamp in nanoseconds.

§Arguments
  • &Self - The limiter instance.
  • u64 - Monotonic timestamp in nanoseconds.
  • u64 - Number of quota units to consume.
§Returns
  • RateLimitDecision - Admission decision and nanosecond timings.
Source

pub fn peek(&self) -> RateLimitDecision

Inspects current availability without consuming quota.

§Arguments
  • &Self - The limiter instance.
§Returns
  • RateLimitDecision - Non-mutating availability snapshot.
Source

pub fn peek_at_ns(&self, now_ns: u64) -> RateLimitDecision

Inspects availability at an explicit monotonic timestamp without consuming quota.

§Arguments
  • &Self - The limiter instance.
  • u64 - Monotonic timestamp in nanoseconds.
§Returns
  • RateLimitDecision - Non-mutating availability snapshot.
Source

pub fn reset(&self)

Resets the limiter counter back to zero.

§Arguments
  • &Self - The limiter instance.

Trait Implementations§

Source§

impl Debug for FixedWindowLimiter

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more

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 = !

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

fn try_from(value: U) -> Result<T, !>

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.