pub struct RateLimiter { /* private fields */ }Expand description
Rate limiter for download and upload bandwidth.
Cloning a RateLimiter shares the underlying token buckets — all clones
draw from the same pool. The hot path (acquire_download / acquire_upload)
performs no mutex acquisition: token accounting is done entirely via
atomic CAS operations on the inner TokenBuckets.
Implementations§
Source§impl RateLimiter
impl RateLimiter
pub fn new(config: &RateLimiterConfig) -> Self
pub fn unlimited() -> Self
pub async fn acquire_download(&self, bytes: u64)
pub async fn acquire_upload(&self, bytes: u64)
Sourcepub async fn try_acquire_download(&self, bytes: u64) -> bool
pub async fn try_acquire_download(&self, bytes: u64) -> bool
Non-blocking attempt to acquire download tokens.
Returns true if tokens were available, false otherwise (no wait).
Sourcepub async fn try_acquire_upload(&self, bytes: u64) -> bool
pub async fn try_acquire_upload(&self, bytes: u64) -> bool
Non-blocking attempt to acquire upload tokens.
Returns true if tokens were available, false otherwise (no wait).
pub fn is_download_limited(&self) -> bool
pub fn is_upload_limited(&self) -> bool
pub async fn config(&self) -> RateLimiterConfig
Sourcepub fn set_download_rate(&self, rate: Option<u64>)
pub fn set_download_rate(&self, rate: Option<u64>)
Dynamically update the download rate limit.
None or Some(0) means unlimited (no throttling).
Some(rate) where rate > 0 sets the new rate in bytes/sec.
Sourcepub fn set_upload_rate(&self, rate: Option<u64>)
pub fn set_upload_rate(&self, rate: Option<u64>)
Dynamically update the upload rate limit.
Same semantics as set_download_rate.
Trait Implementations§
Source§impl Clone for RateLimiter
impl Clone for RateLimiter
Source§fn clone(&self) -> RateLimiter
fn clone(&self) -> RateLimiter
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more