pub struct GCRA;Expand description
GCRA (Generic Cell Rate Algorithm) rate limiter.
This is the recommended algorithm for most use cases, offering:
- Precise rate control with even request spacing
- Low memory usage
- Excellent burst handling
- Clear “retry after” semantics
§Example
ⓘ
use oc_ratelimit_advanced::{GCRA, Quota, MemoryStorage};
use std::time::Duration;
let algorithm = GCRA::new();
let storage = MemoryStorage::new();
let quota = Quota::per_second(10).with_burst(15);
let decision = algorithm.check_and_record(&storage, "user:123", "a).await?;Implementations§
Trait Implementations§
Source§impl Algorithm for GCRA
impl Algorithm for GCRA
Source§async fn check_and_record<S: Storage>(
&self,
storage: &S,
key: &str,
quota: &Quota,
) -> Result<Decision>
async fn check_and_record<S: Storage>( &self, storage: &S, key: &str, quota: &Quota, ) -> Result<Decision>
Check if a request is allowed AND record it atomically. Read more
Auto Trait Implementations§
impl Freeze for GCRA
impl RefUnwindSafe for GCRA
impl Send for GCRA
impl Sync for GCRA
impl Unpin for GCRA
impl UnwindSafe for GCRA
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