pub struct ZeroCopyTokenBucket { /* private fields */ }Expand description
Zero-copy token bucket implementation
This implementation optimizes for minimal allocations by:
- Using borrowed string references for lookups
- Only allocating when inserting new keys
- Avoiding intermediate string copies
Note: flurry’s current API requires String keys, so we still need to allocate on first access. However, subsequent accesses to the same key avoid allocation during the lookup phase.
Implementations§
Trait Implementations§
Source§impl Algorithm for ZeroCopyTokenBucket
impl Algorithm for ZeroCopyTokenBucket
Source§fn check<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<RateLimitDecision>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn check<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<RateLimitDecision>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Checks if a request for the given key should be permitted. Read more
Source§fn check_with_cost<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
cost: u64,
) -> Pin<Box<dyn Future<Output = Result<RateLimitDecision>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn check_with_cost<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
cost: u64,
) -> Pin<Box<dyn Future<Output = Result<RateLimitDecision>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Checks if a request with the given cost should be permitted. Read more
Auto Trait Implementations§
impl Freeze for ZeroCopyTokenBucket
impl RefUnwindSafe for ZeroCopyTokenBucket
impl Send for ZeroCopyTokenBucket
impl Sync for ZeroCopyTokenBucket
impl Unpin for ZeroCopyTokenBucket
impl UnwindSafe for ZeroCopyTokenBucket
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