pub enum Stat<T> {
Known {
value: T,
class: Class,
},
Unknown,
}Expand description
One statistic, or the honest absence of one.
Known carries the value and how much to trust it. Unknown is what a question has no answer
to, and the whole design rests on callers treating it as a case rather than as a zero.
Variants§
Known
A value, and what kind of knowledge it is.
Fields
value: TThe number, bound, flag or set the question asked for.
Unknown
No answer. Not a zero, not a one and not a default.
Implementations§
Source§impl<T> Stat<T>
impl<T> Stat<T>
Sourcepub const fn exact(value: T) -> Self
pub const fn exact(value: T) -> Self
A value that was counted, compared or maintained rather than guessed.
Sourcepub const fn certified(value: T, bound: f64) -> Self
pub const fn certified(value: T, bound: f64) -> Self
A value wrong by no more than bound as a fraction of itself.
Sourcepub const fn is_unknown(&self) -> bool
pub const fn is_unknown(&self) -> bool
Whether there is no answer.
Sourcepub const fn value(&self) -> Option<&T>
pub const fn value(&self) -> Option<&T>
The value, whatever its class, for a decision that only chooses between equivalent plans.
Sourcepub const fn exact_value(&self) -> Option<&T>
pub const fn exact_value(&self) -> Option<&T>
The value, but only when it is exact.
The one door for a decision that changes an answer if the number is wrong. Folding a
predicate away, narrowing arithmetic, dropping an aggregate: all of them ask here, and all of
them take today’s path when the answer is None. See spec/stats/05-every-query.md section
5.10, which is where the rule is stated and where the warning about breaking it in good faith
is written down.
Sourcepub const fn class(&self) -> Option<Class>
pub const fn class(&self) -> Option<Class>
How much of the answer is knowledge, or None when there is no answer.
Sourcepub fn unwrap_or(self, default: T) -> T
pub fn unwrap_or(self, default: T) -> T
The value, or what the caller decided to do without one.
Sourcepub fn map<U>(self, f: impl FnOnce(T) -> U) -> Stat<U>
pub fn map<U>(self, f: impl FnOnce(T) -> U) -> Stat<U>
The same answer about a different quantity, with the class carried across unchanged.
For a transformation that cannot lose knowledge, such as reading a row count as a byte count through a fixed width. A transformation that does lose knowledge should build its answer with the class it deserves rather than mapping.