[−][src]Struct twitchchat::RateLimit
A leaky-bucket style token-based rate limiter
Implementations
impl RateLimit
[src]
pub fn from_class(rate_class: RateClass) -> Self
[src]
feature="tokio"
only.Create a rate limit from a RateClass
pub fn new(cap: u64, initial: u64, period: Duration) -> Self
[src]
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]
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]
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]
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]
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]
feature="tokio"
only.Take a single token, returning how many are available
This'll block the task if none are available
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for RateLimit
impl Send for RateLimit
impl Sync for RateLimit
impl Unpin for RateLimit
impl UnwindSafe for RateLimit
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<T> ToOwned for T where
T: Clone,
[src]
T: Clone,
type Owned = T
The resulting type after obtaining ownership.
fn to_owned(&self) -> T
[src]
fn clone_into(&self, target: &mut T)
[src]
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<V, T> VZip<V> for T where
V: MultiLane<T>,
V: MultiLane<T>,