DynamicMapping

Struct DynamicMapping 

Source
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>

Source

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.
Source

pub fn tokens(&self, key: &K, capacity: u64, period: Duration) -> u64

Source

pub fn next_reset(&self, key: &K, capacity: u64, period: Duration) -> Duration

Source

pub fn retry_after( &self, key: &K, capacity: u64, period: Duration, ) -> Option<Duration>

Source

pub fn can_trigger(&self, key: &K, capacity: u64, period: Duration) -> bool

Source

pub fn trigger( &self, key: &K, capacity: u64, period: Duration, ) -> Option<Duration>

Source

pub fn reset(&self, key: &K, capacity: u64, period: Duration)

Source

pub fn cycle(&self) -> bool

Cycles the mapping. Returns true if it cycled, or false if not.

Source

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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.