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§
Sourcetype Semantic: DataSemantic
type Semantic: DataSemantic
The type of data semantic associated with samples.
Sourcetype Aggregation: Clone
type Aggregation: Clone
The type of the statistical aggregation.
Required Methods§
Sourcefn fold(&mut self, sample: Self::Sample) -> Result<(), FoldError>
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.
Sourcefn reset(&mut self)
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 SamplingInterval
s.
Statistics can be configured to reset to any given state via Reset
.
LatchMax
crate::experimental::series::statistic::LatchMax
Reset
crate::experimental::series::statistic::Reset
Sourcefn aggregation(&self) -> Option<Self::Aggregation>
fn aggregation(&self) -> Option<Self::Aggregation>
Gets the statistical aggregation.
Returns None
if no aggregation is ready.
Provided Methods§
Sourcefn fill(
&mut self,
sample: Self::Sample,
n: NonZeroUsize,
) -> Result<(), FoldError>
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 Statistic
s, 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.