pub fn consume(&mut self, tokens: u64, token_type: TokenType) -> bool {
        // Identify the required token bucket.
        let token_bucket = match token_type {
            TokenType::Bytes => self.bandwidth.as_mut(),
            TokenType::Ops => self.ops.as_mut(),
        };
        // Try to consume from the token bucket.
        let success = match token_bucket {
            Some(bucket) => bucket.reduce(tokens),
            // If bucket is not present rate limiting is disabled on token type,
            // consume() will always succeed.
            None => true,
        };
        // When we report budget is over, there will be no further calls here,
        // register a timer to replenish the bucket and resume processing;
        // make sure there is only one running timer for this limiter.
        if !success && !self.timer_active {
            // Register the timer; don't care about its previous state
            // safe to unwrap: timer is definitely Some() since we have a bucket.
            self.timer_fd
                .set_state(TIMER_REFILL_STATE, SetTimeFlags::Default);
            self.timer_active = true;
        }
        success
    }
/// Attempts to consume tokens and returns whether that is possible.
///
/// If rate limiting is disabled on provided `token_type`, this function will always succeed.
Attempts to consume tokens and returns whether that is possible.
If rate limiting is disabled on provided `token_type`, this function will always succeed.
Attempts to consume tokens and returns whether that is possible . If rate limiting is disabled on provided ` token_type ` this function will always succeed .
pub fn consume(&mut self, tokens: u64, token_type: TokenType) -> bool {
        // Identify the required token bucket.
        let token_bucket = match token_type {
            TokenType::Bytes => self.bandwidth.as_mut(),
            TokenType::Ops => self.ops.as_mut(),
        };
        // Try to consume from the token bucket.
        let success = match token_bucket {
            Some(bucket) => bucket.reduce(tokens),
            // If bucket is not present rate limiting is disabled on token type,
            // consume() will always succeed.
            None => true,
        };
        // When we report budget is over, there will be no further calls here,
        // register a timer to replenish the bucket and resume processing;
        // make sure there is only one running timer for this limiter.
        if !success && !self.timer_active {
            // Register the timer; don't care about its previous state
            // safe to unwrap: timer is definitely Some() since we have a bucket.
            self.timer_fd
                .set_state(TIMER_REFILL_STATE, SetTimeFlags::Default);
            self.timer_active = true;
        }
        success
    }
pub fn consume ( & mut self , tokens : u64 , token_type : TokenType ) -> bool { // Identify the required token bucket. let token_bucket = match token_type { TokenType :: Bytes => self . bandwidth . as_mut ( ) , TokenType :: Ops => self . ops . as_mut ( ) , } ; // Try to consume from the token bucket. let success = match token_bucket { Some ( bucket ) => bucket . reduce ( tokens ) , // If bucket is not present rate limiting is disabled on token type, // consume() will always succeed. None => true , } ; // When we report budget is over, there will be no further calls here, // register a timer to replenish the bucket and resume processing; // make sure there is only one running timer for this limiter. if ! success && ! self . timer_active { // Register the timer; don't care about its previous state // safe to unwrap: timer is definitely Some() since we have a bucket. self . timer_fd . set_state ( TIMER_REFILL_STATE , SetTimeFlags :: Default ) ; self . timer_active = true ; } success }
Attempts to consume tokens and returns whether that is possible.
Attempts to consume tokens and returns whether that is possible .
&mut self
tokens
u64
token_type
TokenType
&mut self
tokens
u64
token_type
TokenType