pub struct RateLimit { /* private fields */ }Expand description
Rate limit information from GitHub API response headers.
GitHub includes rate limit information in HTTP response headers:
X-RateLimit-Limit: Maximum requests allowed per hourX-RateLimit-Remaining: Requests remaining in current windowX-RateLimit-Reset: Unix timestamp when the rate limit resets
§Examples
use github_bot_sdk::client::RateLimit;
use chrono::{Utc, Duration};
let reset_time = Utc::now() + Duration::hours(1);
let rate_limit = RateLimit::new(5000, 4500, reset_time, "core");
assert!(!rate_limit.is_exhausted());
assert!(rate_limit.remaining() > 1000);Implementations§
Source§impl RateLimit
impl RateLimit
Sourcepub fn new(
limit: u32,
remaining: u32,
reset_at: DateTime<Utc>,
resource: impl Into<String>,
) -> Self
pub fn new( limit: u32, remaining: u32, reset_at: DateTime<Utc>, resource: impl Into<String>, ) -> Self
Create a new rate limit from GitHub API response.
§Arguments
limit- Maximum requests allowedremaining- Requests remainingreset_at- When the limit resetsresource- The resource type (default “core”)
Sourcepub fn is_exhausted(&self) -> bool
pub fn is_exhausted(&self) -> bool
Check if the rate limit is exhausted (no requests remaining).
Sourcepub fn is_near_exhaustion(&self, margin: f64) -> bool
pub fn is_near_exhaustion(&self, margin: f64) -> bool
Check if we’re close to exhausting the rate limit.
§Arguments
margin- The safety margin as a fraction (0.0 to 1.0)
Returns true if remaining requests are below the margin threshold.
§Examples
let rate_limit = RateLimit::new(5000, 400, Utc::now(), "core");
// Check if we're below 10% remaining
assert!(rate_limit.is_near_exhaustion(0.1));Trait Implementations§
Auto Trait Implementations§
impl Freeze for RateLimit
impl RefUnwindSafe for RateLimit
impl Send for RateLimit
impl Sync for RateLimit
impl Unpin for RateLimit
impl UnsafeUnpin for RateLimit
impl UnwindSafe for RateLimit
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more