Struct RealTimeRunningAverage

Source
pub struct RealTimeRunningAverage<V: Default, TS: TimeSource = RealTimeSource> { /* private fields */ }
Expand description

Represents running average calculation window where shift and measurement are using given time source to obtain value of now instant. It is using specified window width that will consist of given number of accumulator buckets to ensure constant memory usage.

Implementations§

Source§

impl<V: Default> RealTimeRunningAverage<V, RealTimeSource>

Source

pub fn new(duration: Duration) -> RealTimeRunningAverage<V, RealTimeSource>

Crate new instance with window of given width duration and using RealTimeSource as time source for now instant. Note: new() is parametrizing output to RealTimeSource as this cannot be inferred otherwise.

Source§

impl<V: Default, TS: TimeSource> RealTimeRunningAverage<V, TS>

Source

pub fn with_time_source( duration: Duration, capacity: usize, time_source: TS, ) -> RealTimeRunningAverage<V, TS>

Crate new instance with window of given width duration and using given as time source for now instant.

Source

pub fn insert(&mut self, val: V)
where V: AddAssign<V>,

Insert value to be average over now. Panics if time source time goes backwards.

Source

pub fn measurement<'i>(&'i mut self) -> Measurement<V>
where V: Sum<&'i V>,

Calculate running average using time window ending now. Panics if time source time goes backwards.

Source

pub fn time_source(&mut self) -> &mut TS

Return mutable reference to time source used.

Trait Implementations§

Source§

impl<V: Debug + Default, TS: Debug + TimeSource> Debug for RealTimeRunningAverage<V, TS>
where TS::Instant: Debug,

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<V: Default> Default for RealTimeRunningAverage<V, RealTimeSource>

Source§

fn default() -> RealTimeRunningAverage<V, RealTimeSource>

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl<V, TS> Freeze for RealTimeRunningAverage<V, TS>
where TS: Freeze, <TS as TimeSource>::Instant: Freeze,

§

impl<V, TS> RefUnwindSafe for RealTimeRunningAverage<V, TS>

§

impl<V, TS> Send for RealTimeRunningAverage<V, TS>
where TS: Send, <TS as TimeSource>::Instant: Send, V: Send,

§

impl<V, TS> Sync for RealTimeRunningAverage<V, TS>
where TS: Sync, <TS as TimeSource>::Instant: Sync, V: Sync,

§

impl<V, TS> Unpin for RealTimeRunningAverage<V, TS>
where TS: Unpin, <TS as TimeSource>::Instant: Unpin, V: Unpin,

§

impl<V, TS> UnwindSafe for RealTimeRunningAverage<V, TS>

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.