Struct QueueStats

Source
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> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.