pub struct MethodAwareRateLimiter { /* private fields */ }Expand description
A method-aware rate limiter that automatically looks up CU costs per RPC method.
Wraps a TokenBucket with a CuCostTable so callers only need to
supply the method name — the correct compute-unit cost is resolved
internally.
Implementations§
Source§impl MethodAwareRateLimiter
impl MethodAwareRateLimiter
Sourcepub fn new(config: RateLimiterConfig, cost_table: CuCostTable) -> Self
pub fn new(config: RateLimiterConfig, cost_table: CuCostTable) -> Self
Create a new method-aware rate limiter.
Sourcepub fn try_acquire_method(&self, method: &str) -> bool
pub fn try_acquire_method(&self, method: &str) -> bool
Acquire tokens for a specific RPC method, using its CU cost.
Returns true if the method’s cost was successfully consumed from the
bucket, false if the bucket has insufficient tokens (rate limited).
Sourcepub fn wait_time_for_method(&self, method: &str) -> Duration
pub fn wait_time_for_method(&self, method: &str) -> Duration
Wait time before the given method can be called.
Sourcepub fn bucket(&self) -> &TokenBucket
pub fn bucket(&self) -> &TokenBucket
Access the underlying bucket for manual control.
Auto Trait Implementations§
impl !Freeze for MethodAwareRateLimiter
impl RefUnwindSafe for MethodAwareRateLimiter
impl Send for MethodAwareRateLimiter
impl Sync for MethodAwareRateLimiter
impl Unpin for MethodAwareRateLimiter
impl UnsafeUnpin for MethodAwareRateLimiter
impl UnwindSafe for MethodAwareRateLimiter
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