Skip to main content

FixedWindowCell

Struct FixedWindowCell 

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

Lock-free single-AtomicU64 fixed-window state cell packing (window_id, count).

Implementations§

Source§

impl FixedWindowCell

Lock-free atomic fixed-window operations on FixedWindowCell.

Source

pub fn new() -> Self

Creates an empty FixedWindowCell initialized at window 0, count 0.

Source

pub fn reset(&self)

Resets the cell back to window 0 with count 0.

§Arguments
  • &Self - The fixed-window cell.
Source

pub fn is_idle_at_ns(&self, config: &FixedWindowConfig, now_ns: u64) -> bool

Returns whether the cell has no active usage in the current window at now_ns.

§Arguments
  • &Self - The fixed-window cell.
  • &FixedWindowConfig - Fixed-window configuration.
  • u64 - Current monotonic timestamp in nanoseconds.
§Returns
  • bool - true when the cell belongs to a prior window or has count 0.
Source

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

Inspects current fixed-window availability at now_ns without mutating state.

§Arguments
  • &Self - The fixed-window cell.
  • &FixedWindowConfig - Fixed-window configuration.
  • u64 - Current monotonic timestamp in nanoseconds.
§Returns
  • RateLimitDecision - Non-mutating availability snapshot.
Source

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

Atomically checks and consumes cost units at monotonic timestamp now_ns.

§Arguments
  • &Self - The fixed-window cell.
  • &FixedWindowConfig - Fixed-window configuration.
  • u64 - Current monotonic timestamp in nanoseconds.
  • u64 - Request cost in units.
§Returns
  • RateLimitDecision - Admission decision and nanosecond timings.

Trait Implementations§

Source§

impl Debug for FixedWindowCell

Source§

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

Formats the value using the given formatter. Read more
Source§

impl Default for FixedWindowCell

Default empty FixedWindowCell initialized at window 0, count 0.

Source§

fn default() -> Self

Creates a FixedWindowCell at window 0 with zero usage.

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.