pub struct DynamicMapping<K: Eq + Hash + Clone + Send + Sync + 'static> { /* private fields */ }Expand description
Similar to floodgate::FixedMapping, except that each cooldown can have
a different capacity and/or period.
For some method documentation, please see floodgate::JumpingWindow.
Implementations§
Source§impl<K: Eq + Hash + Clone + Send + Sync + 'static> DynamicMapping<K>
impl<K: Eq + Hash + Clone + Send + Sync + 'static> DynamicMapping<K>
Sourcepub fn new(cycle_period: Duration) -> Self
pub fn new(cycle_period: Duration) -> Self
Create a new DynamicMapping.
§Arguments
cycle_period- How often to cycle the mapping. Must be greater than the period of any cooldown this mapping contains.
pub fn tokens(&self, key: &K, capacity: u64, period: Duration) -> u64
pub fn next_reset(&self, key: &K, capacity: u64, period: Duration) -> Duration
pub fn retry_after( &self, key: &K, capacity: u64, period: Duration, ) -> Option<Duration>
pub fn can_trigger(&self, key: &K, capacity: u64, period: Duration) -> bool
pub fn trigger( &self, key: &K, capacity: u64, period: Duration, ) -> Option<Duration>
pub fn reset(&self, key: &K, capacity: u64, period: Duration)
Sourcepub fn start(mapping: Arc<Self>)
pub fn start(mapping: Arc<Self>)
Start the background cycler. Failing to do this will result in a memory leak.
If, for some reason, you don’t want to use the default cycler, you must manually call
the .cycle method on the mapping periodically.
§Arguments
mapping- The DynamicMapping, wrapped in an Arc.
Auto Trait Implementations§
impl<K> !Freeze for DynamicMapping<K>
impl<K> !RefUnwindSafe for DynamicMapping<K>
impl<K> Send for DynamicMapping<K>
impl<K> Sync for DynamicMapping<K>
impl<K> Unpin for DynamicMapping<K>
impl<K> UnwindSafe for DynamicMapping<K>where
K: UnwindSafe,
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