Module fact
Expand description
A value that carries its measure, its provenance and its as-of.
A number on screen is a claim. Measured keeps the three things that make it honest
together, so an app cannot render the number without also having the answer to “measured
how?”, “from where?” and “when?”: a Measure naming what it counts and its unit, a source
naming where the reading came from, and an as-of instant that makes it age on screen
(stale past its own expected interval).
Unknown is a designed state, not zero: Measured::unknown carries the reason (and the
action that would resolve it) and renders an em dash. A number is never a stand-in for “we
did not measure”.
The type is what a view renders, not a widget: Measured::value_or_dash in the value
position, Measured::caption under it (provenance is always the caption line, never
beside the value), and Measured::is_stale dimming the provenance rather than the value.
use tilo_ui::fact::{Measure, Measured};
use tilo_ui::time::{Duration, UNIX_EPOCH};
let at = UNIX_EPOCH + Duration::from_secs(120);
let memory = Measured::known(
Measure::new("Memory in use").unit("GiB"),
"8.6",
"this device",
at,
Some(Duration::from_secs(5)),
);
assert_eq!(memory.value_or_dash(), "8.6");
assert!(!memory.is_stale(at + Duration::from_secs(2)));