Skip to main content

DurationP

Enum DurationP 

Source
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

Source

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.

Source

pub fn projected_secs_f64(seconds: f64) -> Result<DurationP, Error>

A hypothetical phase, from seconds a caller supplied as a float.

Source

pub fn duration(self) -> Duration

The span, without its label. Named so a call site that drops the provenance is visible as one.

Source

pub fn provenance(self) -> Provenance

How this duration is known.

Source

pub fn seconds(self) -> Decimal

The span as exact decimal seconds, for the money path.

Source

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

Source

pub fn is_measured(self) -> bool

True only for a timed span. Read by CostReport::fully_measured.

Trait Implementations§

Source§

impl Clone for DurationP

Source§

fn clone(&self) -> DurationP

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 Copy for DurationP

Source§

impl Debug for DurationP

Source§

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

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

impl Display for DurationP

The Python’s f"{seconds:g}s ({provenance})", so a report line reads the same in either client.

Source§

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

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

impl Eq for DurationP

Source§

impl Hash for DurationP

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 PartialEq for DurationP

Source§

fn eq(&self, other: &DurationP) -> bool

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

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

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for DurationP

Auto Trait Implementations§

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> AsOut<T> for T
where T: Copy,

Source§

fn as_out(&mut self) -> Out<'_, T>

Returns an out reference to self.
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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Checks if this value is equivalent to the given key. Read more
Source§

impl<Q, K> Equivalent<K> for Q
where Q: Eq + ?Sized, K: Borrow<Q> + ?Sized,

Source§

fn equivalent(&self, key: &K) -> bool

Compare self to key and return true if they are equal.
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T> Instrument for T

Source§

fn instrument(self, span: Span) -> Instrumented<Self> ⓘ

Instruments this type with the provided Span, returning an Instrumented wrapper. Read more
Source§

fn in_current_span(self) -> Instrumented<Self> ⓘ

Instruments this type with the current Span, returning an Instrumented wrapper. Read more
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> IntoEither for T

Source§

fn into_either(self, into_left: bool) -> Either<Self, Self> ⓘ

Converts self into a Left variant of Either<Self, Self> if into_left is true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

fn into_either_with<F>(self, into_left: F) -> Either<Self, Self> ⓘ
where F: FnOnce(&Self) -> bool,

Converts self into a Left variant of Either<Self, Self> if into_left(&self) returns true. Converts self into a Right variant of Either<Self, Self> otherwise. Read more
Source§

impl<Unshared, Shared> IntoShared<Shared> for Unshared
where Shared: FromUnshared<Unshared>,

Source§

fn into_shared(self) -> Shared

Creates a shared type from an unshared type.
Source§

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

Source§

fn and<P, B, E>(self, other: P) -> And<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow only if self and other return Action::Follow. Read more
Source§

fn or<P, B, E>(self, other: P) -> Or<T, P>
where T: Sized + Policy<B, E>, P: Policy<B, E>,

Create a new Policy that returns Action::Follow if either self or other returns Action::Follow. Read more
Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
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> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

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

Source§

type Error = !

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

impl<T> WithSubscriber for T

Source§

fn with_subscriber<S>(self, subscriber: S) -> WithDispatch<Self> ⓘ
where S: Into<Dispatch>,

Attaches the provided Subscriber to this type, returning a WithDispatch wrapper. Read more
Source§

fn with_current_subscriber(self) -> WithDispatch<Self> ⓘ

Attaches the current default Subscriber to this type, returning a WithDispatch wrapper. Read more