Function refill_tokens_with_time_adjustment

Source
pub fn refill_tokens_with_time_adjustment(
    current_tokens: usize,
    max_tokens: usize,
    last_refresh: Instant,
    now: Instant,
    window_duration: Duration,
) -> (usize, Instant)
Expand description

Calculate tokens available after time-based refill

Higher-level function that combines token calculation and proportional time adjustment. This is the main function used by rate limiters to update their state.

§Arguments

  • current_tokens - Current number of available tokens
  • max_tokens - Maximum number of tokens in the bucket
  • last_refresh - The last refresh time
  • now - Current time
  • window_duration - Duration of the rate limiting window

§Returns

A tuple of (new_token_count, new_last_refresh_time)