pub enum Approximation<T, E> {
Exact(T),
Inexact(T, E),
}Expand description
Represent an calculation result with a possible error.
Variants§
Exact(T)
The result is exact, contains the result value
Inexact(T, E)
The result is inexact, contains the result value and error
Implementations§
Source§impl<T, E> Approximation<T, E>
impl<T, E> Approximation<T, E>
Sourcepub fn value_with_exact(self) -> (T, bool)
pub fn value_with_exact(self) -> (T, bool)
The value together with whether the computation was exact.
The boolean is true for an exact result and false for an inexact one; the error E is
discarded (use error when the error magnitude matters). Handy for the
“value + exactness flag” pattern (e.g. MPFR’s exact flag, which a Ziv closure needs to
report a zero radius for an exactly-representable result).
Sourcepub fn error(self) -> Option<E>
pub fn error(self) -> Option<E>
Return the error if the result is inexact, None if it is exact.
Sourcepub const fn error_ref(&self) -> Option<&E>
pub const fn error_ref(&self) -> Option<&E>
Borrow the error if the result is inexact, None if it is exact.
Sourcepub fn map<U, F>(self, f: F) -> Approximation<U, E>where
F: FnOnce(T) -> U,
pub fn map<U, F>(self, f: F) -> Approximation<U, E>where
F: FnOnce(T) -> U,
Map the result value to a new type, preserving the error (if any).
Sourcepub fn and_then<U, F>(self, f: F) -> Approximation<U, E>where
F: FnOnce(T) -> Approximation<U, E>,
pub fn and_then<U, F>(self, f: F) -> Approximation<U, E>where
F: FnOnce(T) -> Approximation<U, E>,
Chain a fallible mapping that itself returns an Approximation, combining the
errors: an inexact input or an inexact result both yield an inexact result.
Trait Implementations§
Source§impl<T: Clone, E: Clone> Clone for Approximation<T, E>
impl<T: Clone, E: Clone> Clone for Approximation<T, E>
Source§fn clone(&self) -> Approximation<T, E>
fn clone(&self) -> Approximation<T, E>
1.0.0 (const: unstable) · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read more