pub fn try_dequeue(&mut self) -> DequeueResult<T> {
        if self.queue.is_empty() {
            return DequeueResult::Empty;
        }

        if self.allowance > 0 {
            self.allowance -= 1;
            return self.queue.pop_front().into();
        }

        let now = Instant::now();
        let elapsed = now.duration_since(self.timepoint);

        match self.interval.checked_sub(elapsed) {
            Some(rest) => DequeueResult::Limit(rest),
            None => {
                self.allowance = self.quantum - 1;
                self.timepoint = now;
                self.queue.pop_front().into()
            }
        }
    }
/// Tries to remove the first element and return it.
///
/// # Examples
///
/// ```
/// # use std::time::Duration;
/// use rate_limit_queue::{RateLimitQueue, DequeueResult};
///
/// let mut queue = RateLimitQueue::new(2, Duration::from_secs(10));
/// queue.enqueue(1);
/// queue.enqueue(2);
///
/// assert_eq!(queue.try_dequeue(), DequeueResult::Data(1));
/// assert_eq!(queue.try_dequeue(), DequeueResult::Data(2));
/// assert_eq!(queue.try_dequeue(), DequeueResult::Empty);
///
/// queue.enqueue(3);
/// assert!(queue.try_dequeue().is_limit());
/// ```
Tries to remove the first element and return it.
Tries to remove the first element and return it .
pub fn try_dequeue(&mut self) -> DequeueResult<T> {
        if self.queue.is_empty() {
            return DequeueResult::Empty;
        }
        if self.allowance > 0 {
            self.allowance -= 1;
            return self.queue.pop_front().into();
        }
        let now = Instant::now();
        let elapsed = now.duration_since(self.timepoint);
        match self.interval.checked_sub(elapsed) {
            Some(rest) => DequeueResult::Limit(rest),
            None => {
                self.allowance = self.quantum - 1;
                self.timepoint = now;
                self.queue.pop_front().into()
            }
        }
    }
pub fn try_dequeue ( & mut self ) -> DequeueResult < T > { if self . queue . is_empty ( ) { return DequeueResult :: Empty ; } if self . allowance > 0 { self . allowance -= 1 ; return self . queue . pop_front ( ) . into ( ) ; } let now = Instant :: now ( ) ; let elapsed = now . duration_since ( self . timepoint ) ; match self . interval . checked_sub ( elapsed ) { Some ( rest ) => DequeueResult :: Limit ( rest ) , None => { self . allowance = self . quantum - 1 ; self . timepoint = now ; self . queue . pop_front ( ) . into ( ) } } }
Tries to remove the first element and return it.
Tries to remove the first element and return it .
&mut self
&mut self
examples
None
use std::time::duration;
use rate_limit_queue::{RateLimitQueue, DequeueResult}.

let mut queue = RateLimitQueue::new(2, Duration::from_secs(10));
queue.enqueue(1);
queue.enqueue(2).

assert_eq!(queue.try_dequeue(), DequeueResult::Data(1));
assert_eq!(queue.try_dequeue(), DequeueResult::Data(2));
assert_eq!(queue.try_dequeue(), DequeueResult::Empty).

queue.enqueue(3);
assert!(queue.try_dequeue().is_limit());
```
use rate_limit_queue :: { RateLimitQueue DequeueResult } . let mut queue = RateLimitQueue :: new ( 2 Duration :: from_secs ( 10 )) ; queue . enqueue ( 1 ) ; queue . enqueue ( 2 ) . assert_eq! ( queue . try_dequeue () DequeueResult :: Data ( 1 )) ; assert_eq! ( queue . try_dequeue () DequeueResult :: Data ( 2 )) ; assert_eq! ( queue . try_dequeue () DequeueResult :: Empty ) . queue . enqueue ( 3 ) ; assert! ( queue . try_dequeue () . is_limit () ) ; ` ` `