Skip to main content

Stat

Enum Stat 

Source
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: T

The number, bound, flag or set the question asked for.

§class: Class

How much of it is known rather than guessed.

§

Unknown

No answer. Not a zero, not a one and not a default.

Implementations§

Source§

impl<T> Stat<T>

Source

pub const fn exact(value: T) -> Self

A value that was counted, compared or maintained rather than guessed.

Source

pub const fn certified(value: T, bound: f64) -> Self

A value wrong by no more than bound as a fraction of itself.

Source

pub const fn estimated(value: T, source: Source) -> Self

A guess, and where it came from.

Source

pub const fn is_known(&self) -> bool

Whether there is an answer at all.

Source

pub const fn is_unknown(&self) -> bool

Whether there is no answer.

Source

pub const fn value(&self) -> Option<&T>

The value, whatever its class, for a decision that only chooses between equivalent plans.

Source

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.

Source

pub const fn class(&self) -> Option<Class>

How much of the answer is knowledge, or None when there is no answer.

Source

pub fn unwrap_or(self, default: T) -> T

The value, or what the caller decided to do without one.

Source

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.

Source

pub fn zip<U, V>(self, other: Stat<U>, f: impl FnOnce(T, U) -> V) -> Stat<V>

An answer computed from two, unknown when either is unknown, classed by Class::combine.

Trait Implementations§

Source§

impl<T: Clone> Clone for Stat<T>

Source§

fn clone(&self) -> Stat<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 Stat<T>

Source§

impl<T: Debug> Debug for Stat<T>

Source§

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

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

impl<T> Default for Stat<T>

Source§

fn default() -> Self

Unknown, because a statistic nobody filled in is a statistic nobody knows.

Source§

impl<T: Display> Display for Stat<T>

Source§

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

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

impl<T: PartialEq> PartialEq for Stat<T>

Source§

fn eq(&self, other: &Stat<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 Stat<T>

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

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

§

impl<T> UnwindSafe for Stat<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> 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, !>

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.