Skip to main content

MetricState

Enum MetricState 

Source
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).

Fields

§value: T

The retained value.

§age: Duration

How long ago value was actually measured.

§

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.

§

TemporarilyUnavailable(UnavailableReason)

Normally available, absent from this sample.

Implementations§

Source§

impl<T> MetricState<T>

Source

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.

Source

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.

Source

pub const fn is_available(&self) -> bool

Whether this sample measured the metric.

Source

pub const fn is_stale(&self) -> bool

Whether a retained value is being shown instead of a fresh one.

Source

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).

Source

pub const fn is_warming_up(&self) -> bool

Whether the metric is expected to become available shortly.

Source

pub fn map<U, F: FnOnce(T) -> U>(self, f: F) -> MetricState<U>

Transforms the contained value, preserving the availability state.

Source

pub const fn as_ref(&self) -> MetricState<&T>

Borrows the contained value.

Source

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).

Source

pub const fn symbol(&self) -> char

A single-character redundant cue, so meaning survives without color (§5.2).

Source

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>

Source§

fn clone(&self) -> MetricState<T>

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl<T: Copy> Copy for MetricState<T>

Source§

impl<T: Debug> Debug for MetricState<T>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T: Eq> Eq for MetricState<T>

Source§

impl<T> From<Option<T>> for MetricState<T>

Source§

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.

Source§

impl<T: Hash> Hash for MetricState<T>

Source§

fn hash<__H: Hasher>(&self, state: &mut __H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl<T: PartialEq> PartialEq for MetricState<T>

Source§

fn eq(&self, other: &MetricState<T>) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl<T: PartialEq> StructuralPartialEq for MetricState<T>

Auto Trait Implementations§

§

impl<T> Freeze for MetricState<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for MetricState<T>
where T: RefUnwindSafe,

§

impl<T> Send for MetricState<T>
where T: Send,

§

impl<T> Sync for MetricState<T>
where T: Sync,

§

impl<T> Unpin for MetricState<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for MetricState<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for MetricState<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.