pub fn calculate_token_refill(
elapsed: Duration,
window_duration: Duration,
max_tokens: usize,
current_tokens: usize,
) -> usizeExpand description
Calculate the number of tokens to refill based on elapsed time
This function implements the standard proportional token refill algorithm used across all rate limiter implementations. It calculates how many tokens should be available based on the time elapsed since the last refresh.
§Arguments
elapsed- Time elapsed since last refreshwindow_duration- Duration of the rate limiting windowmax_tokens- Maximum number of tokens in the bucketcurrent_tokens- Current number of available tokens
§Returns
The new number of available tokens (capped at max_tokens)