pub struct RateLimiter { /* private fields */ }Expand description
Manages API rate limiting with intelligent backoff.
Thread-safe via internal RwLock. All methods take &self.
Implementations§
Source§impl RateLimiter
impl RateLimiter
Sourcepub fn new(config: &RateLimiterConfig) -> Self
pub fn new(config: &RateLimiterConfig) -> Self
Create a new rate limiter with the given configuration.
Sourcepub async fn should_wait(&self) -> bool
pub async fn should_wait(&self) -> bool
Returns true if a request should wait before proceeding.
Only returns true when the API has explicitly rate-limited us
and the rate limiter is enabled.
Sourcepub async fn wait(&self) -> Result<()>
pub async fn wait(&self) -> Result<()>
Blocks until it’s safe to make a request. Only blocks when actually rate-limited by the API.
Sourcepub async fn update_from_headers(&self, info: &RateLimitInfo)
pub async fn update_from_headers(&self, info: &RateLimitInfo)
Updates rate limit state from API response headers.
A successful response (with rate limit headers) confirms the client is no longer in a consecutive rate-limit run, so the backoff counter is reset.
Sourcepub async fn mark_rate_limited(&self, reset_time: DateTime<Utc>)
pub async fn mark_rate_limited(&self, reset_time: DateTime<Utc>)
Marks that the API has returned a 429 rate-limit response.
Sourcepub async fn get_status(&self) -> RateLimitStatus
pub async fn get_status(&self) -> RateLimitStatus
Returns a snapshot of the current rate limit status.
Sourcepub async fn is_near_limit(&self, threshold: f64) -> bool
pub async fn is_near_limit(&self, threshold: f64) -> bool
Returns true if usage has exceeded the given threshold (0.0–1.0).
Sourcepub async fn is_rate_limited(&self) -> bool
pub async fn is_rate_limited(&self) -> bool
Returns true if the API has rate-limited us and the window hasn’t reset.