Function calculate_token_refill_ns

Source
pub fn calculate_token_refill_ns(
    elapsed_ns: u64,
    window_ns: u64,
    max_tokens: usize,
    current_tokens: usize,
) -> usize
Expand description

Calculate token refill for nanosecond-based rate limiters

Specialized version for rate limiters that work with nanosecond timestamps instead of Duration/Instant types.

§Arguments

  • elapsed_ns - Nanoseconds elapsed since last refresh
  • window_ns - Duration of the rate limiting window in nanoseconds
  • max_tokens - Maximum number of tokens in the bucket
  • current_tokens - Current number of available tokens

§Returns

The new number of available tokens (capped at max_tokens)