[][src]Struct twitchchat::rate_limit::RateLimit

pub struct RateLimit { /* fields omitted */ }

A leaky-bucket style token-based rate limiter

Implementations

impl RateLimit[src]

pub fn set_cap(&mut self, cap: u64)[src]

Overwrite the current capacity with this value

pub fn set_period(&mut self, period: Duration)[src]

Overwrite the current period with this value

pub fn get_cap(&self) -> u64[src]

Get the current capacity with this value

pub fn get_period(&self) -> Duration[src]

Get the current period with this value

pub fn from_class(rate_class: RateClass) -> Self[src]

Create a rate limit from a RateClass

pub fn new(cap: u64, initial: u64, period: Duration) -> Self[src]

Create a new rate limiter of capacity with an initial number of token and the period between refills

pub fn full(cap: u64, period: Duration) -> Self[src]

Create a new rate limiter that is pre-filled

cap is the number of total tokens available

period is how long it'll take to refill all of the tokens

pub fn empty(cap: u64, period: Duration) -> Self[src]

Create am empty rate limiter

cap is the number of total tokens available

period is how long it'll take to refill all of the tokens

This will block, at first, atleast one period until its filled

pub fn get_available_tokens(&self) -> u64[src]

Get the current available tokens

pub fn get_current_rate_class(&self) -> Option<RateClass>[src]

Tries to get the current RateClass.

pub fn consume(&mut self, tokens: u64) -> Result<u64, Duration>[src]

Consume a specific ammount of tokens

Returns

  • Successful consumption (e.g. not blocking) will return how many tokens are left
  • Failure to consume (e.g. out of tokens) will return a Duration of when the bucket will be refilled

Trait Implementations

impl Clone for RateLimit[src]

impl Debug for RateLimit[src]

impl Default for RateLimit[src]

Auto Trait Implementations

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> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

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.