pub struct RateLimiter { /* private fields */ }Expand description
Thread-safe rate limit tracker for GitHub API operations.
Tracks rate limits for different GitHub API resources and authentication contexts (app-level vs installation-level) and provides methods to check rate limits before making requests.
§Examples
use github_bot_sdk::client::{RateLimiter, RateLimitContext};
use github_bot_sdk::auth::InstallationId;
let rate_limiter = RateLimiter::new(0.1); // 10% safety margin
// Check if we can make an app-level request
if rate_limiter.can_proceed(&RateLimitContext::App, "core") {
// Make API request
}
// Check if we can make an installation-level request
let install_id = InstallationId::new(12345);
if rate_limiter.can_proceed(&RateLimitContext::Installation(install_id), "core") {
// Make API request
}Implementations§
Source§impl RateLimiter
impl RateLimiter
Sourcepub fn update_from_headers(
&self,
context: &RateLimitContext,
headers: &HeaderMap,
)
pub fn update_from_headers( &self, context: &RateLimitContext, headers: &HeaderMap, )
Update rate limit information from response headers.
§Arguments
context- The authentication context (app or installation)headers- HTTP response headers containing rate limit info
Sourcepub fn can_proceed(&self, context: &RateLimitContext, resource: &str) -> bool
pub fn can_proceed(&self, context: &RateLimitContext, resource: &str) -> bool
Check if we can proceed with a request for the given context and resource.
§Arguments
context- The authentication context (app or installation)resource- The resource type (e.g., “core”, “search”)
§Returns
true if we have sufficient rate limit remaining (considering safety margin),
false if we’re at or near the rate limit.
Trait Implementations§
Source§impl Clone for RateLimiter
impl Clone for RateLimiter
Source§fn clone(&self) -> RateLimiter
fn clone(&self) -> RateLimiter
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreSource§impl Debug for RateLimiter
impl Debug for RateLimiter
Auto Trait Implementations§
impl Freeze for RateLimiter
impl RefUnwindSafe for RateLimiter
impl Send for RateLimiter
impl Sync for RateLimiter
impl Unpin for RateLimiter
impl UnsafeUnpin for RateLimiter
impl UnwindSafe for RateLimiter
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