#[non_exhaustive]pub struct RateLimiter { /* private fields */ }Expand description
Token bucket rate limiter — allows burst up to capacity, refills over time.
Implementations§
Source§impl RateLimiter
impl RateLimiter
Sourcepub fn new(capacity: u32, refill_rate: f64) -> Self
pub fn new(capacity: u32, refill_rate: f64) -> Self
Create a new rate limiter.
capacity = max burst size, refill_rate = tokens per second.
Sourcepub fn check(&self, key: &str) -> bool
pub fn check(&self, key: &str) -> bool
Try to consume one token for the given key (tool name or container ID). Returns true if allowed, false if rate limited.
Sourcepub fn remove(&self, key: &str) -> bool
pub fn remove(&self, key: &str) -> bool
Remove a single key’s bucket. Returns true if the key existed.
Sourcepub fn cleanup_stale(&self, max_age: Duration)
pub fn cleanup_stale(&self, max_age: Duration)
Remove all entries whose last activity is older than max_age.
Should be called periodically (e.g. every 5 minutes) to prevent unbounded growth of the bucket map.
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