[][src]Struct twitchchat::RateLimit

pub struct RateLimit { /* fields omitted */ }

A leaky-bucket style token-based rate limiter

Implementations

impl RateLimit[src]

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

This is supported on feature="tokio" only.

Create a rate limit from a RateClass

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

This is supported on feature="tokio" only.

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]

This is supported on feature="tokio" only.

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]

This is supported on feature="tokio" only.

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 consume(&mut self, tokens: u64) -> Result<u64, Duration>[src]

This is supported on feature="tokio" only.

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

pub async fn throttle<'_>(&'_ mut self, tokens: u64) -> u64[src]

This is supported on feature="tokio" only.

Throttle the current task, consuming a specific amount of tokens and possibly blocking until tokens are available

Returns

the amount of tokens remaining

pub async fn take<'_>(&'_ mut self) -> u64[src]

This is supported on feature="tokio" only.

Take a single token, returning how many are available

This'll block the task if none are available

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.