[−][src]Struct twitchchat::rate_limit::RateLimit
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
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,
pub 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.
pub fn to_owned(&self) -> T
[src]
pub 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.
pub 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>,