Statistic

Trait Statistic 

Source
pub trait Statistic: Clone {
    type Semantic: DataSemantic;
    type Sample: Clone;
    type Aggregation: Clone;

    // Required methods
    fn fold(&mut self, sample: Self::Sample) -> Result<(), FoldError>;
    fn reset(&mut self);
    fn aggregation(&self) -> Option<Self::Aggregation>;

    // Provided method
    fn fill(
        &mut self,
        sample: Self::Sample,
        n: NonZeroUsize,
    ) -> Result<(), FoldError> { ... }
}
Expand description

A statistical function type that folds samples into an aggregation.

Required Associated Types§

Source

type Semantic: DataSemantic

The type of data semantic associated with samples.

Source

type Sample: Clone

The type of samples.

Source

type Aggregation: Clone

The type of the statistical aggregation.

Required Methods§

Source

fn fold(&mut self, sample: Self::Sample) -> Result<(), FoldError>

Folds a sample into the aggregation of the statistic.

§Errors

Returns an error if folding the sample causes an overflow.

Source

fn reset(&mut self)

Resets the state (and aggregation) of the statistic.

The state of a statistic after a reset is arbitrary, but most types reset to a reasonable initial state via Default. Some types do nothing, such as LatchMax, which operates across SamplingIntervals.

Statistics can be configured to reset to any given state via Reset.

LatchMax crate::experimental::series::statistic::LatchMax Reset crate::experimental::series::statistic::Reset

Source

fn aggregation(&self) -> Option<Self::Aggregation>

Gets the statistical aggregation.

Returns None if no aggregation is ready.

Provided Methods§

Source

fn fill( &mut self, sample: Self::Sample, n: NonZeroUsize, ) -> Result<(), FoldError>

Folds a sample into the aggregation of a statistic n (one or more) times.

For some Statistics, this function is significantly more efficient than multiple calls to [fold]. For example, Max need not fold more than once for any given sample regardless of n. Prefer this function when the same sample must be folded more than once.

§Errors

Returns an error if folding the sample causes an overflow.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementors§

Source§

impl Statistic for ArithmeticMean<f32>

Source§

impl Statistic for ArithmeticMean<i64>

Source§

impl Statistic for ArithmeticMean<u64>

Source§

impl Statistic for LatchMax<u64>

Source§

impl Statistic for Sum<i64>

Source§

impl Statistic for Sum<u64>

Source§

impl Statistic for Union<u64>

Source§

impl<A, F, R> Statistic for PostAggregation<F, R>
where F: Statistic, R: Clone + Fn(F::Aggregation) -> A, A: Clone,

Source§

impl<F, R> Statistic for Reset<F, R>
where F: Statistic, R: Clone + FnMut() -> F,

Source§

impl<T> Statistic for Last<T>
where T: Copy + Zero + Num + NumCast,

Source§

impl<T> Statistic for Max<T>
where T: Ord + Copy + Zero + Num + NumCast,

Source§

impl<T> Statistic for Min<T>
where T: Ord + Copy + Zero + Num + NumCast,