pub struct InMemoryDistributedBackend { /* private fields */ }Expand description
In-process distributed rate-limit backend.
Uses a single tokio::sync::Mutex guarding a HashMap so that the entire
acquire/refill cycle for any key is one atomic critical section. This makes
it correct for concurrent in-process workers and a faithful local stand-in
for a Redis backend during tests.
Although it shares one mutex across all keys (simple and contention-safe for tests and single-process deployments), the public contract only promises per-key atomicity, so a future sharded implementation remains compatible.
Implementations§
Trait Implementations§
Source§impl Debug for InMemoryDistributedBackend
impl Debug for InMemoryDistributedBackend
Source§impl Default for InMemoryDistributedBackend
impl Default for InMemoryDistributedBackend
Source§impl DistributedRateLimitBackend for InMemoryDistributedBackend
impl DistributedRateLimitBackend for InMemoryDistributedBackend
Source§fn acquire<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
cost: f64,
params: RateLimitParams,
) -> Pin<Box<dyn Future<Output = Result<AcquireOutcome>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn acquire<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
cost: f64,
params: RateLimitParams,
) -> Pin<Box<dyn Future<Output = Result<AcquireOutcome>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn available<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
params: RateLimitParams,
) -> Pin<Box<dyn Future<Output = Result<f64>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn available<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
params: RateLimitParams,
) -> Pin<Box<dyn Future<Output = Result<f64>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Report the currently available permits for
key (after refill). Read moreSource§fn time_until_available<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
cost: f64,
params: RateLimitParams,
) -> Pin<Box<dyn Future<Output = Result<Duration>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn time_until_available<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
cost: f64,
params: RateLimitParams,
) -> Pin<Box<dyn Future<Output = Result<Duration>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Source§fn reset<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
fn reset<'life0, 'life1, 'async_trait>(
&'life0 self,
key: &'life1 str,
) -> Pin<Box<dyn Future<Output = Result<()>> + Send + 'async_trait>>where
Self: 'async_trait,
'life0: 'async_trait,
'life1: 'async_trait,
Clear all stored state for
key. Read moreSource§fn backend_name(&self) -> &str
fn backend_name(&self) -> &str
Backend name, for diagnostics.
Auto Trait Implementations§
impl !Freeze for InMemoryDistributedBackend
impl !RefUnwindSafe for InMemoryDistributedBackend
impl !UnwindSafe for InMemoryDistributedBackend
impl Send for InMemoryDistributedBackend
impl Sync for InMemoryDistributedBackend
impl Unpin for InMemoryDistributedBackend
impl UnsafeUnpin for InMemoryDistributedBackend
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