Struct eternity::Bucket[][src]

pub struct Bucket<Key, Value = ()> where
    Key: Hash + PartialEq + Clone + Eq + Send + Sync,
    Value: Clone + Send
{ /* fields omitted */ }

This type checks for rate limits on Keys.
If caching is enabled, it will cache values.

Implementations

impl<Key: Hash + PartialEq + Clone + Eq + Send + Sync, Value: Clone + Send> Bucket<Key, Value>[src]

pub async fn hit_limit(&mut self, key: &Key) -> Option<RateLimitInfo<Value>>[src]

Tries to perform a hit in the bucket. If no hit can be performed, this method will return the rate limit. Otherwise, the method will return None.

pub async fn hit_or_cache(
    &mut self,
    key: &Key,
    function: impl Future<Output = Option<Value>> + Send
) -> Option<Value>
[src]

First, checks the bucket for a potential rate limit. If a rate limit applies, it will clone the cached value. If no value is cached, this method returns None. If no rate limit applies, this method will run function and if some value is returned by that function, caches the value.

pub async fn add_cache_value(&mut self, key: &Key, value: Value)[src]

Inserts a cache value into the group of key.

Auto Trait Implementations

impl<Key, Value> RefUnwindSafe for Bucket<Key, Value> where
    Key: RefUnwindSafe,
    Value: RefUnwindSafe

impl<Key, Value> Send for Bucket<Key, Value>

impl<Key, Value> Sync for Bucket<Key, Value> where
    Value: Sync

impl<Key, Value> Unpin for Bucket<Key, Value> where
    Key: Unpin,
    Value: Unpin

impl<Key, Value> UnwindSafe for Bucket<Key, Value> where
    Key: UnwindSafe,
    Value: UnwindSafe

Blanket Implementations

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

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

The type returned in the event of a conversion error.