pub struct QueueStats<T: Ord + Add<Output = T>> {
pub min: Option<T>,
pub max: Option<T>,
pub sum: Option<T>,
pub len: usize,
}
Expand description
Stats of the queue.
It provides the following statistics: min and max value in the queue, the sum of all the values and the length of all elements hold in the queue.
The values are computed taking into account only the existent elements in the queue, and not past elements removed because expiration or because they were removed.
You can get the stats object calling to
the SumQueue::stats()
method of the queue:
use std::time::Duration;
use sum_queue::SumQueue;
let mut queue = SumQueue::new(Duration::from_millis(800));
queue.push(-1);
queue.push(5);
queue.push(2);
let stats = queue.stats();
assert_eq!(stats.min, Some(-1));
assert_eq!(stats.max, Some(5));
assert_eq!(stats.sum, Some(6));
assert_eq!(stats.len, 3);
But you can also get the stats while pushing elements, which it’s more efficient than push and then get the stats:
use std::time::Duration;
use sum_queue::SumQueue;
let mut queue = SumQueue::new(Duration::from_secs(1000));
queue.push(-1);
queue.push(5);
let stats = queue.push_and_stats(2);
assert_eq!(stats.min, Some(-1));
assert_eq!(stats.max, Some(5));
assert_eq!(stats.sum, Some(6));
assert_eq!(stats.len, 3);
Fields§
§min: Option<T>
min value of the queue
max: Option<T>
max value of the queue
sum: Option<T>
sum of all the values in the queue
len: usize
size of the queue, same than SumQueue::len()
Auto Trait Implementations§
impl<T> Freeze for QueueStats<T>where
T: Freeze,
impl<T> RefUnwindSafe for QueueStats<T>where
T: RefUnwindSafe,
impl<T> Send for QueueStats<T>where
T: Send,
impl<T> Sync for QueueStats<T>where
T: Sync,
impl<T> Unpin for QueueStats<T>where
T: Unpin,
impl<T> UnwindSafe for QueueStats<T>where
T: UnwindSafe,
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more