Struct ratelimit_rs::Bucket [−][src]
Bucket
represents a token bucket that fills at a predetermined rate. Methods on
Bucket
may be called concurrently.
Fields
capacity: u64
capacity holds the overall capacity of the bucket.
available_tokens: u64
availableTokens holds the number of available tokens as of the associated latestTick. It will be negative when there are consumers waiting for tokens.
quantum: u64
quantum holds how many tokens are added on each tick.
fill_interval: Duration
fillInterval holds the interval between each tick.
latest_tick: Instant
latestTick holds the latest tick for which we know the number of tokens in the bucket.
Implementations
impl Bucket
[src]
pub fn new(
fill_interval: Duration,
capacity: u64,
quantum: u64,
available_tokens: u64
) -> Self
[src]
fill_interval: Duration,
capacity: u64,
quantum: u64,
available_tokens: u64
) -> Self
pub fn take_available(&mut self, count: u64) -> u64
[src]
TakeAvailable takes up to count immediately available tokens from the bucket. It returns the number of tokens removed, or zero if there are no available tokens. It does not block.
pub fn take_one_available(&mut self) -> u64
[src]
TakeOneAvailable takes up a token from the bucket.
pub fn take_max_duration(
&mut self,
count: u64,
max_wait: Duration
) -> (Duration, bool)
[src]
&mut self,
count: u64,
max_wait: Duration
) -> (Duration, bool)
TakeMaxDuration is take, except that it will only take tokens from the bucket if the wait time for the tokens is no greater than maxWait. If it would take longer than maxWait for the tokens to become available, it does nothing and reports false, otherwise it returns the time that the caller should wait until the tokens are actually available, and reports true.
pub fn wait_max_duration(&mut self, count: u64, max_wait: Duration) -> bool
[src]
WaitMaxDuration is like Wait except that it will only take tokens from the bucket if it needs to wait for no greater than maxWait. It reports whether any tokens have been removed from the bucket If no tokens have been removed, it returns immediately.
Trait Implementations
Auto Trait Implementations
impl RefUnwindSafe for Bucket
impl Send for Bucket
impl Sync for Bucket
impl Unpin for Bucket
impl UnwindSafe for Bucket
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, 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>,