pub enum DurationP {
Measured(Duration),
Projected(Duration),
}Expand description
Seconds, plus how we know them (COST-1).
The labelling rule is the enum: every way of building one of these names a
provenance, because there is no other variant to reach and no
From<Duration>/Default to fall into. cost.py achieved the same thing with
a field that had no default, so Duration(3600) raised TypeError — the whole
rule collapses the moment an unlabelled duration can be written, because the
label that goes missing is always the weaker one, and here it cannot be written.
Wrapping std::time::Duration also retires the Python’s negativity check: a
negative duration is not a value this type can hold, so an inverted clock is
caught at duration_of_secs_f64 or never enters at all.
§Provenance cannot be omitted (COST-1)
“No unlabelled constructor” is a claim about what does not exist, so it is checked by programs that do not build:
Each carries its expected error code, because a bare compile_fail passes for any
build failure at all — a typo in the test would leave the guard green.
// There is no `From<Duration> for DurationP`, so a bare span cannot become a
// labelled one by coercion.
let unlabelled: DurationP = Duration::from_secs(3600).into();// No `Default` either. A default would have to pick a provenance, and the one it
// would pick is the stronger claim.
let unlabelled = DurationP::default();The positive case, for contrast — naming the provenance is the only way in, and it is one word:
let timed = DurationP::Measured(Duration::from_secs(3600));
assert_eq!(timed.provenance(), Provenance::Measured);Variants§
Measured(Duration)
A clock ran and this is what it read.
Projected(Duration)
A hypothetical: an estimate’s input, or a documented minimum nobody timed.
Implementations§
Source§impl DurationP
impl DurationP
Sourcepub fn measured_secs_f64(seconds: f64) -> Result<DurationP, Error>
pub fn measured_secs_f64(seconds: f64) -> Result<DurationP, Error>
A timed phase, from seconds a caller measured as a float.
Fallible because the float is: see duration_of_secs_f64.
Sourcepub fn projected_secs_f64(seconds: f64) -> Result<DurationP, Error>
pub fn projected_secs_f64(seconds: f64) -> Result<DurationP, Error>
A hypothetical phase, from seconds a caller supplied as a float.
Sourcepub fn duration(self) -> Duration
pub fn duration(self) -> Duration
The span, without its label. Named so a call site that drops the provenance is visible as one.
Sourcepub fn provenance(self) -> Provenance
pub fn provenance(self) -> Provenance
How this duration is known.
Sourcepub fn seconds_f64(self) -> f64
pub fn seconds_f64(self) -> f64
The span as an f64, for a JSON envelope.
Lossy, and named so, exactly like
ResidencyComparison::break_even_seconds_f64. The exact answer is
DurationP::seconds; this exists because cli.py:743 emits a line item’s
duration.seconds as a JSON number and the two clients’ envelopes have to be
substitutable. Seconds, not dollars — no money figure has an f64 accessor
(COST-2), and that asymmetry is the whole rule: a consumer doing arithmetic on
a duration should not have to branch on which client produced the envelope,
while a consumer doing arithmetic on a dollar figure should be reading the
string and told so.
(cli.py line numbers resolve at git show 'c4d396e^:clients/python/src/microvms_agentd/cli.py' — the retired oracle.)
Sourcepub fn is_measured(self) -> bool
pub fn is_measured(self) -> bool
True only for a timed span. Read by CostReport::fully_measured.
Trait Implementations§
impl Copy for DurationP
Source§impl Display for DurationP
The Python’s f"{seconds:g}s ({provenance})", so a report line reads the same in
either client.
impl Display for DurationP
The Python’s f"{seconds:g}s ({provenance})", so a report line reads the same in
either client.
impl Eq for DurationP
impl StructuralPartialEq for DurationP
Auto Trait Implementations§
impl Freeze for DurationP
impl RefUnwindSafe for DurationP
impl Send for DurationP
impl Sync for DurationP
impl Unpin for DurationP
impl UnsafeUnpin for DurationP
impl UnwindSafe for DurationP
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
Source§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.