pub struct MemoryRateLimitStore { /* private fields */ }Expand description
A RateLimitStore in this process’s memory: the limits of every app it
is registered in are counted together. For tests, and for several apps
in one process.
use std::time::Duration;
use navree_http::MemoryRateLimitStore;
let store = MemoryRateLimitStore::default();
let minute = Duration::from_secs(60);
assert!(store.check("exports:ada", 1, minute).is_ok());
assert!(store.check("exports:ada", 1, minute).is_err());Implementations§
Trait Implementations§
Source§impl Debug for MemoryRateLimitStore
impl Debug for MemoryRateLimitStore
Source§impl Default for MemoryRateLimitStore
impl Default for MemoryRateLimitStore
Source§impl RateLimitStore for MemoryRateLimitStore
impl RateLimitStore for MemoryRateLimitStore
Source§fn hit<'a>(
&'a self,
key: &'a str,
limit: u32,
per: Duration,
) -> BoxFuture<'a, StoreVerdict>
fn hit<'a>( &'a self, key: &'a str, limit: u32, per: Duration, ) -> BoxFuture<'a, StoreVerdict>
Counts a request against
key: at most limit (at least 1) per
per, as a burst, then one every per / limit, by the generic cell
rate algorithm as KeyedRateLimiter counts. A refused request does
not count, and Limited::report is set on the first refusal of key
in a window of per.Auto Trait Implementations§
impl !RefUnwindSafe for MemoryRateLimitStore
impl Forget for MemoryRateLimitStore
impl Freeze for MemoryRateLimitStore
impl Move for MemoryRateLimitStore
impl Send for MemoryRateLimitStore
impl Sync for MemoryRateLimitStore
impl Unpin for MemoryRateLimitStore
impl UnsafeUnpin for MemoryRateLimitStore
impl UnwindSafe for MemoryRateLimitStore
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