pub struct RateLimitInfo {
pub remaining: Option<u32>,
pub limit: Option<u32>,
pub retry_after: Option<u64>,
}Expand description
Rate limit information from API response headers.
Fields§
§remaining: Option<u32>Number of requests remaining in the current window.
limit: Option<u32>Total request limit for the current window.
retry_after: Option<u64>Seconds until the rate limit resets.
Implementations§
Source§impl RateLimitInfo
impl RateLimitInfo
Sourcepub fn new() -> Self
pub fn new() -> Self
Creates a new rate limit info.
Examples found in repository?
examples/base_error_handling.rs (line 102)
100fn demonstrate_rate_limiting() {
101 // Create rate limit info from API response headers
102 let info = RateLimitInfo::new()
103 .with_remaining(0)
104 .with_limit(200)
105 .with_retry_after(60);
106
107 println!(" Rate limit status:");
108 println!(" - Remaining: {:?}", info.remaining);
109 println!(" - Limit: {:?}", info.limit);
110 println!(" - Retry after: {:?} seconds", info.retry_after);
111 println!(" - Is limited: {}", info.is_limited());
112
113 // Create error with full rate limit info
114 let error = AlpacaError::rate_limit_with_info(info);
115 println!(" Error: {}", error);
116}Sourcepub fn with_remaining(self, remaining: u32) -> Self
pub fn with_remaining(self, remaining: u32) -> Self
Sets the remaining requests.
Examples found in repository?
examples/base_error_handling.rs (line 103)
100fn demonstrate_rate_limiting() {
101 // Create rate limit info from API response headers
102 let info = RateLimitInfo::new()
103 .with_remaining(0)
104 .with_limit(200)
105 .with_retry_after(60);
106
107 println!(" Rate limit status:");
108 println!(" - Remaining: {:?}", info.remaining);
109 println!(" - Limit: {:?}", info.limit);
110 println!(" - Retry after: {:?} seconds", info.retry_after);
111 println!(" - Is limited: {}", info.is_limited());
112
113 // Create error with full rate limit info
114 let error = AlpacaError::rate_limit_with_info(info);
115 println!(" Error: {}", error);
116}Sourcepub fn with_limit(self, limit: u32) -> Self
pub fn with_limit(self, limit: u32) -> Self
Sets the limit.
Examples found in repository?
examples/base_error_handling.rs (line 104)
100fn demonstrate_rate_limiting() {
101 // Create rate limit info from API response headers
102 let info = RateLimitInfo::new()
103 .with_remaining(0)
104 .with_limit(200)
105 .with_retry_after(60);
106
107 println!(" Rate limit status:");
108 println!(" - Remaining: {:?}", info.remaining);
109 println!(" - Limit: {:?}", info.limit);
110 println!(" - Retry after: {:?} seconds", info.retry_after);
111 println!(" - Is limited: {}", info.is_limited());
112
113 // Create error with full rate limit info
114 let error = AlpacaError::rate_limit_with_info(info);
115 println!(" Error: {}", error);
116}Sourcepub fn with_retry_after(self, seconds: u64) -> Self
pub fn with_retry_after(self, seconds: u64) -> Self
Sets the retry after duration in seconds.
Examples found in repository?
examples/base_error_handling.rs (line 105)
100fn demonstrate_rate_limiting() {
101 // Create rate limit info from API response headers
102 let info = RateLimitInfo::new()
103 .with_remaining(0)
104 .with_limit(200)
105 .with_retry_after(60);
106
107 println!(" Rate limit status:");
108 println!(" - Remaining: {:?}", info.remaining);
109 println!(" - Limit: {:?}", info.limit);
110 println!(" - Retry after: {:?} seconds", info.retry_after);
111 println!(" - Is limited: {}", info.is_limited());
112
113 // Create error with full rate limit info
114 let error = AlpacaError::rate_limit_with_info(info);
115 println!(" Error: {}", error);
116}Sourcepub fn is_limited(&self) -> bool
pub fn is_limited(&self) -> bool
Returns true if rate limited.
Examples found in repository?
examples/base_error_handling.rs (line 111)
100fn demonstrate_rate_limiting() {
101 // Create rate limit info from API response headers
102 let info = RateLimitInfo::new()
103 .with_remaining(0)
104 .with_limit(200)
105 .with_retry_after(60);
106
107 println!(" Rate limit status:");
108 println!(" - Remaining: {:?}", info.remaining);
109 println!(" - Limit: {:?}", info.limit);
110 println!(" - Retry after: {:?} seconds", info.retry_after);
111 println!(" - Is limited: {}", info.is_limited());
112
113 // Create error with full rate limit info
114 let error = AlpacaError::rate_limit_with_info(info);
115 println!(" Error: {}", error);
116}Trait Implementations§
Source§impl Clone for RateLimitInfo
impl Clone for RateLimitInfo
Source§fn clone(&self) -> RateLimitInfo
fn clone(&self) -> RateLimitInfo
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 RateLimitInfo
impl Debug for RateLimitInfo
Source§impl Default for RateLimitInfo
impl Default for RateLimitInfo
Source§fn default() -> RateLimitInfo
fn default() -> RateLimitInfo
Returns the “default value” for a type. Read more
Auto Trait Implementations§
impl Freeze for RateLimitInfo
impl RefUnwindSafe for RateLimitInfo
impl Send for RateLimitInfo
impl Sync for RateLimitInfo
impl Unpin for RateLimitInfo
impl UnwindSafe for RateLimitInfo
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