pub fn consume(&mut self, tokens: u64) -> Result<u64, Duration> {
        let Self { bucket, .. } = self;

        let now = Instant::now();
        if let Some(n) = bucket.refill(now) {
            bucket.tokens = std::cmp::min(bucket.tokens + n, self.cap);
        }

        if tokens <= bucket.tokens {
            bucket.tokens -= tokens;
            bucket.backoff = 0;
            return Ok(bucket.tokens);
        }

        let prev = bucket.tokens;
        Err(bucket.estimate(tokens - prev, now))
    }
/// 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
Consume a specific ammount of tokens
Consume a specific ammount of tokens
pub fn consume(&mut self, tokens: u64) -> Result<u64, Duration> {
        let Self { bucket, .. } = self;
        let now = Instant::now();
        if let Some(n) = bucket.refill(now) {
            bucket.tokens = std::cmp::min(bucket.tokens + n, self.cap);
        }
        if tokens <= bucket.tokens {
            bucket.tokens -= tokens;
            bucket.backoff = 0;
            return Ok(bucket.tokens);
        }
        let prev = bucket.tokens;
        Err(bucket.estimate(tokens - prev, now))
    }
pub fn consume ( & mut self , tokens : u64 ) -> Result < u64 , Duration > { let Self { bucket , .. } = self ; let now = Instant :: now ( ) ; if let Some ( n ) = bucket . refill ( now ) { bucket . tokens = std :: cmp :: min ( bucket . tokens + n , self . cap ) ; } if tokens <= bucket . tokens { bucket . tokens -= tokens ; bucket . backoff = 0 ; return Ok ( bucket . tokens ) ; } let prev = bucket . tokens ; Err ( bucket . estimate ( tokens - prev , now ) ) }
Consume a specific ammount of tokens
Consume a specific ammount of tokens
&mut self
tokens
u64
Successful consumption  will return how many tokens
are left
Failure to consume  will return a Duration of when
the bucket will be refilled
Successful consumption will return how many tokens are left Failure to consume will return a Duration of when the bucket will be refilled
&mut self
tokens
u64