pub enum MetricState<T> {
Available(T),
Stale {
value: T,
age: Duration,
},
WarmingUp,
PermissionDenied,
Unsupported,
TemporarilyUnavailable(UnavailableReason),
}Expand description
The availability of a single metric in a single sample.
The Stale variant is an addition to the five states listed in §4. It exists
because §4 also states that a temporarily unavailable metric may retain its
last good value only if that value is visibly marked stale and carries its
age. Encoding the value and its age in the type makes it impossible to render
a retained value without knowing it is stale.
Variants§
Available(T)
Measured in this sample.
Stale
The last known-good value, retained across a transient failure.
Must be rendered with a visible stale marker and age (§4).
WarmingUp
The metric needs more samples before it means anything (§8.2, §26).
The first sample of delta-based data is not zero.
PermissionDenied
The OS refused the read. Not a fatal error (§9.2).
Unsupported
This platform does not expose the metric at all.
Normally available, absent from this sample.
Implementations§
Source§impl<T> MetricState<T>
impl<T> MetricState<T>
Sourcepub const fn fresh(&self) -> Option<&T>
pub const fn fresh(&self) -> Option<&T>
The freshly measured value, if this sample actually measured it.
Returns None for stale values. Use this for anything that feeds a
calculation, a diagnostic rule, or a rate baseline.
Sourcepub const fn displayable(&self) -> Option<(&T, Duration)>
pub const fn displayable(&self) -> Option<(&T, Duration)>
The best available value, fresh or stale, paired with its age.
Use this only for display, and only alongside the returned age so the staleness can be shown.
Sourcepub const fn is_available(&self) -> bool
pub const fn is_available(&self) -> bool
Whether this sample measured the metric.
Sourcepub const fn is_stale(&self) -> bool
pub const fn is_stale(&self) -> bool
Whether a retained value is being shown instead of a fresh one.
Sourcepub const fn is_unsupported(&self) -> bool
pub const fn is_unsupported(&self) -> bool
Whether the metric will never be available on this platform.
Layout code uses this to drop optional panels when space is scarce (§4).
Sourcepub const fn is_warming_up(&self) -> bool
pub const fn is_warming_up(&self) -> bool
Whether the metric is expected to become available shortly.
Sourcepub fn map<U, F: FnOnce(T) -> U>(self, f: F) -> MetricState<U>
pub fn map<U, F: FnOnce(T) -> U>(self, f: F) -> MetricState<U>
Transforms the contained value, preserving the availability state.
Sourcepub const fn as_ref(&self) -> MetricState<&T>
pub const fn as_ref(&self) -> MetricState<&T>
Borrows the contained value.
Sourcepub const fn placeholder(&self) -> Option<&'static str>
pub const fn placeholder(&self) -> Option<&'static str>
The placeholder to render when there is no value.
Returns None when a value is present. The strings are the ones §4
mandates, and all of them are strict 7-bit ASCII so they are legal in
both glyph modes (§5.1).
Sourcepub const fn symbol(&self) -> char
pub const fn symbol(&self) -> char
A single-character redundant cue, so meaning survives without color (§5.2).
Sourcepub fn into_stale(self, age: Duration) -> Self
pub fn into_stale(self, age: Duration) -> Self
Converts a fresh value into a stale one aged by age.
Collectors call this when a read fails but a previous value is worth
keeping on screen. Anything that is not currently Available is returned
unchanged, so staleness cannot compound into a fake value.
Trait Implementations§
Source§impl<T: Clone> Clone for MetricState<T>
impl<T: Clone> Clone for MetricState<T>
Source§fn clone(&self) -> MetricState<T>
fn clone(&self) -> MetricState<T>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreimpl<T: Copy> Copy for MetricState<T>
Source§impl<T: Debug> Debug for MetricState<T>
impl<T: Debug> Debug for MetricState<T>
impl<T: Eq> Eq for MetricState<T>
Source§impl<T> From<Option<T>> for MetricState<T>
impl<T> From<Option<T>> for MetricState<T>
Source§fn from(value: Option<T>) -> Self
fn from(value: Option<T>) -> Self
Treats a missing optional value as MetricState::Unsupported.
Collectors that know a more specific reason must construct the variant
directly rather than going through Option.