pub struct MeasurementSummary { /* 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. Ordered observations with a mergeable aggregate and a separate latest value.
Count and total saturate independently, tracking actual overflow. An exactly reached numeric cap remains exact; inspect the aggregate’s saturation flags before using raw counts/totals for exact arithmetic. Latest and maximum remain individual observations after overflow. Empty and measured zero are distinct. Consumers own units, identity, ordering and reset boundaries.
Implementations§
Source§impl MeasurementSummary
impl MeasurementSummary
Sourcepub const EMPTY: MeasurementSummary
pub const EMPTY: MeasurementSummary
Empty summary, with no latest or maximum observation.
Sourcepub const fn from_parts(
aggregate: MeasurementAggregate,
latest: Option<u64>,
) -> Result<MeasurementSummary, MeasurementStateError>
pub const fn from_parts( aggregate: MeasurementAggregate, latest: Option<u64>, ) -> Result<MeasurementSummary, MeasurementStateError>
Restore an admitted aggregate and its latest ordered observation.
The caller establishes identity and ordering; this validates numeric fields.
§Errors
Rejects absent/nonempty latest values, values above the maximum and observations inconsistent with the aggregate’s exact total. With an exact count, the other observations cannot contribute more than their maximum.
Sourcepub const fn record(&mut self, value: u64)
pub const fn record(&mut self, value: u64)
Record one completed observation, including zero, in the existing unit.
Sourcepub const fn aggregate(self) -> MeasurementAggregate
pub const fn aggregate(self) -> MeasurementAggregate
Mergeable count/total/maximum snapshot without observation ordering.
Sourcepub const fn samples(self) -> u64
pub const fn samples(self) -> u64
Sample count, clipped at u64::MAX; saturation is in Self::aggregate.
Sourcepub const fn total(self) -> u128
pub const fn total(self) -> u128
Observation total, clipped at u128::MAX; saturation is in Self::aggregate.
Sourcepub const fn mean(self) -> Result<Option<u128>, MeasurementMeanError>
pub const fn mean(self) -> Result<Option<u128>, MeasurementMeanError>
Floor-rounded mean, or None when empty. An exactly reached cap is valid.
§Errors
Returns MeasurementMeanError on actual count or total overflow.
Sourcepub const fn scaled_mean(
self,
scale: u64,
) -> Result<Option<u128>, MeasurementMeanError>
pub const fn scaled_mean( self, scale: u64, ) -> Result<Option<u128>, MeasurementMeanError>
Compute floor(total * scale / samples), retaining fractional information.
Uses the aggregate’s checked projection; a scale of ten reports tenths.
Empty remains None, and scale zero does not conceal actual overflow.
§Errors
Returns MeasurementMeanError for inexact counts/totals or a failed
scaled projection, with the same precedence as the aggregate.
Trait Implementations§
Source§impl Clone for MeasurementSummary
impl Clone for MeasurementSummary
Source§fn clone(&self) -> MeasurementSummary
fn clone(&self) -> MeasurementSummary
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more