pub fn consume(&self, tokens: u64) -> Result<u64, Duration> {
        let now = Instant::now();

        let mut bucket = self.bucket.0.lock().unwrap();
        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))
    }
/// Tries to consume `tokens`
///
/// If it will consume more than available then an Error is returned.
/// Otherwise it returns how many tokens are left
///
/// This error is the `Duration` of the next available time
Tries to consume `tokens`
If it will consume more than available then an Error is returned.
Otherwise it returns how many tokens are left

This error is the `Duration` of the next available time
Tries to consume ` tokens ` If it will consume more than available then an Error is returned . Otherwise it returns how many tokens are left This error is the ` Duration ` of the next available time
pub fn consume(&self, tokens: u64) -> Result<u64, Duration> {
        let now = Instant::now();
        let mut bucket = self.bucket.0.lock().unwrap();
        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 ( & self , tokens : u64 ) -> Result < u64 , Duration > { let now = Instant :: now ( ) ; let mut bucket = self . bucket . 0 . lock ( ) . unwrap ( ) ; 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 ) ) }
Tries to consume `tokens`
If it will consume more than available then an Error is returned.
Tries to consume ` tokens ` If it will consume more than available then an Error is returned .
&self
tokens
u64