pub struct MeasurementAggregate { /* private fields */ }Expand description
Canonical shared arithmetic for local diagnostic summaries and distributions.
Re-exported so callers can name returned summaries without selecting a separate Metrics dependency. This is the shared type, with no local wrapper or arithmetic. Mergeable count, total and maximum in one consumer-selected unit.
Counts and totals clip independently at u64::MAX; sticky flags record actual
overflow, so an exactly reached cap remains exact. Maximum is an individual
observation and remains valid after overflow. There is no latest observation:
unordered batches cannot establish ordering. No allocation or platform reads.
Implementations§
Source§impl MeasurementAggregate
impl MeasurementAggregate
Sourcepub const EMPTY: MeasurementAggregate
pub const EMPTY: MeasurementAggregate
Empty aggregate, without a maximum observation.
Sourcepub const fn record(&mut self, value: u64)
pub const fn record(&mut self, value: u64)
Record one admitted observation, including zero, in the existing unit.
Sourcepub const fn merge(&mut self, other: MeasurementAggregate)
pub const fn merge(&mut self, other: MeasurementAggregate)
Combine observations from a batch without claiming ordering or identity.
Consumers must establish common units and deliberate sample attribution. This is addition, not deduplication: merging the same batch twice records it twice. Source overflow remains sticky even when its clipped value fits.
Sourcepub const fn samples(self) -> u64
pub const fn samples(self) -> u64
Sample count, clipped at u64::MAX; check Self::samples_saturated.
Sourcepub const fn total(self) -> u64
pub const fn total(self) -> u64
Total, clipped at u64::MAX; check Self::total_saturated.
Sourcepub const fn samples_saturated(self) -> bool
pub const fn samples_saturated(self) -> bool
Whether recording or merging has actually overflowed the sample count.
Sourcepub const fn total_saturated(self) -> bool
pub const fn total_saturated(self) -> bool
Whether recording or merging has actually overflowed the value total.
Sourcepub const fn maximum(self) -> Option<u64>
pub const fn maximum(self) -> Option<u64>
Largest observation, or None when empty, including after overflow.
Sourcepub const fn mean(self) -> Result<Option<u64>, MeasurementMeanError>
pub const fn mean(self) -> Result<Option<u64>, MeasurementMeanError>
Floor-rounded mean, or None when empty. Exactly reached caps are valid.
§Errors
Returns MeasurementMeanError::SaturatedSamples before
MeasurementMeanError::SaturatedTotal when actual overflow is recorded.
Sourcepub const fn interval_since(
self,
previous: MeasurementAggregate,
) -> Result<MeasurementInterval, MeasurementIntervalError>
pub const fn interval_since( self, previous: MeasurementAggregate, ) -> Result<MeasurementInterval, MeasurementIntervalError>
Exact count/total difference from an earlier snapshot of this accumulator.
Consumers must first establish matching units, window/reset identity and append-only continuity. This cannot detect a reset followed by numerically larger values or changed attribution. Maxima and latest values are not subtractable and are not returned. Empty intervals differ from added zeros.
§Errors
Rejects sample overflow, total overflow, decreasing samples, decreasing totals, then a changed total with no added samples, in that order.
Trait Implementations§
Source§impl Clone for MeasurementAggregate
impl Clone for MeasurementAggregate
Source§fn clone(&self) -> MeasurementAggregate
fn clone(&self) -> MeasurementAggregate
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more