Skip to main content

GcraCell

Struct GcraCell 

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

Lock-free single-AtomicU64 GCRA state cell usable standalone or inside sharded maps.

Implementations§

Source§

impl GcraCell

Lock-free atomic GCRA operations on GcraCell.

Source

pub fn new() -> Self

Creates an idle GcraCell with zero accumulated arrival debt.

Source

pub fn reset(&self)

Resets the cell back to the idle state (TAT = 0).

§Arguments
  • &Self - The GCRA cell.
Source

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

Returns whether the cell currently has zero accumulated debt at now_ns.

§Arguments
  • &Self - The GCRA cell.
  • u64 - Current monotonic timestamp in nanoseconds.
§Returns
  • bool - true when TAT <= now_ns.
Source

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

Evaluates current quota availability at now_ns without mutating state.

§Arguments
  • &Self - The GCRA cell.
  • &GcraConfig - GCRA configuration.
  • u64 - Current monotonic timestamp in nanoseconds.
§Returns
  • RateLimitDecision - Snapshot decision for a single-unit probe.
Source

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

Atomically checks and consumes cost units at monotonic timestamp now_ns.

§Arguments
  • &Self - The GCRA cell.
  • &GcraConfig - GCRA configuration.
  • u64 - Current monotonic timestamp in nanoseconds.
  • u64 - Request cost in quota units.
§Returns
  • RateLimitDecision - Admission decision and nanosecond timings.

Trait Implementations§

Source§

impl Debug for GcraCell

Source§

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

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

impl Default for GcraCell

Default empty GcraCell initialized at timestamp 0.

Source§

fn default() -> Self

Creates an idle GcraCell with TAT equal to 0.

Auto Trait Implementations§

§

impl !Freeze for GcraCell

§

impl Forget for GcraCell

§

impl Move for GcraCell

§

impl RefUnwindSafe for GcraCell

§

impl Send for GcraCell
where Atomic<u64>: Send,

§

impl Sync for GcraCell
where Atomic<u64>: Sync,

§

impl Unpin for GcraCell
where Align8<u64>: Unpin,

§

impl UnsafeUnpin for GcraCell
where Align8<u64>: UnsafeUnpin,

§

impl UnwindSafe for GcraCell
where Align8<u64>: UnwindSafe,

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.