Debian Codegraph @

src/approx.rs

raw symbols SCIP
1 //! Trait definitions for approximated values
2
3 /// Represent an calculation result with a possible error.
4 #[deriverust-analyzer cargo core https://github.com/rust-lang/rust/library/core macros/builtin/derive:(Debugrust-analyzer cargo core https://github.com/rust-lang/rust/library/core fmt/macros/Debug:, Clonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core clone/Clone:, Copyrust-analyzer cargo core https://github.com/rust-lang/rust/library/core marker/Copy:, PartialEqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/PartialEq:, Eqrust-analyzer cargo core https://github.com/rust-lang/rust/library/core cmp/Eq:)]
5 pub enum Approximationrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#<T, E> {
6 /// The result is exact, contains the result value
7 Exactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Exact#(T),
8
9 /// The result is inexact, contains the result value and error
10 Inexactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Inexact#(T, E),
11 }
12
13 impl<T, E> Approximationrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#<T, E> {
14 /// Get the value of the calculation regardless of error
15 #[inline]
16 pub fn valuerust-analyzer cargo dashu-base 0.4.1 approx/impl#[`Approximation<T, E>`]value().(self) -> T {
17 match self {
18 Selfrust-analyzer cargo dashu-base 0.4.1 approx/impl#[`Approximation<T, E>`]::Exactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Exact#(v) => v,
19 Selfrust-analyzer cargo dashu-base 0.4.1 approx/impl#[`Approximation<T, E>`]::Inexactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Inexact#(v, _) => v,
20 }
21 }
22
23 /// Get a reference to the calculation result
24 #[inline]
25 pub const fn value_refrust-analyzer cargo dashu-base 0.4.1 approx/impl#[`Approximation<T, E>`]value_ref().(&self) -> &T {
26 match self {
27 Selfrust-analyzer cargo dashu-base 0.4.1 approx/impl#[`Approximation<T, E>`]::Exactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Exact#(v) => v,
28 Selfrust-analyzer cargo dashu-base 0.4.1 approx/impl#[`Approximation<T, E>`]::Inexactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Inexact#(v, _) => v,
29 }
30 }
31
32 #[inline]
33 pub fn unwraprust-analyzer cargo dashu-base 0.4.1 approx/impl#[`Approximation<T, E>`]unwrap().(self) -> T {
34 match self {
35 Selfrust-analyzer cargo dashu-base 0.4.1 approx/impl#[`Approximation<T, E>`]::Exactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Exact#(val) => val,
36 Selfrust-analyzer cargo dashu-base 0.4.1 approx/impl#[`Approximation<T, E>`]::Inexactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Inexact#(_, _) => panicrust-analyzer cargo std https://github.com/rust-lang/rust/library/std macros/panic!!("called `Approximation::unwrap()` on a `Inexact` value"),
37 }
38 }
39
40 #[inline]
41 pub fn errorrust-analyzer cargo dashu-base 0.4.1 approx/impl#[`Approximation<T, E>`]error().(self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<E> {
42 match self {
43 Selfrust-analyzer cargo dashu-base 0.4.1 approx/impl#[`Approximation<T, E>`]::Exactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Exact#(_) => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
44 Selfrust-analyzer cargo dashu-base 0.4.1 approx/impl#[`Approximation<T, E>`]::Inexactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Inexact#(_, e) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(e),
45 }
46 }
47
48 #[inline]
49 pub const fn error_refrust-analyzer cargo dashu-base 0.4.1 approx/impl#[`Approximation<T, E>`]error_ref().(&self) -> Optionrust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#<&E> {
50 match self {
51 Selfrust-analyzer cargo dashu-base 0.4.1 approx/impl#[`Approximation<T, E>`]::Exactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Exact#(_) => Nonerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#None#,
52 Selfrust-analyzer cargo dashu-base 0.4.1 approx/impl#[`Approximation<T, E>`]::Inexactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Inexact#(_, e) => Somerust-analyzer cargo core https://github.com/rust-lang/rust/library/core option/Option#Some#(e),
53 }
54 }
55
56 #[inline]
57 pub fn maprust-analyzer cargo dashu-base 0.4.1 approx/impl#[`Approximation<T, E>`]map().<U, F>(self, f: F) -> Approximationrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#<U, E>
58 where
59 F: FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#(T) -> U,
60 {
61 match self {
62 Selfrust-analyzer cargo dashu-base 0.4.1 approx/impl#[`Approximation<T, E>`]::Exactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Exact#(v) => Approximationrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#::Exactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Exact#(f(v)),
63 Selfrust-analyzer cargo dashu-base 0.4.1 approx/impl#[`Approximation<T, E>`]::Inexactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Inexact#(v, e) => Approximationrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#::Inexactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Inexact#(f(v), e),
64 }
65 }
66
67 #[inline]
68 pub fn and_thenrust-analyzer cargo dashu-base 0.4.1 approx/impl#[`Approximation<T, E>`]and_then().<U, F>(self, f: F) -> Approximationrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#<U, E>
69 where
70 F: FnOncerust-analyzer cargo core https://github.com/rust-lang/rust/library/core ops/function/FnOnce#(T) -> Approximationrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#<U, E>,
71 {
72 match self {
73 Selfrust-analyzer cargo dashu-base 0.4.1 approx/impl#[`Approximation<T, E>`]::Exactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Exact#(v) => match f(v) {
74 Approximationrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#::Exactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Exact#(v2) => Approximationrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#::Exactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Exact#(v2),
75 Approximationrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#::Inexactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Inexact#(v2, e) => Approximationrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#::Inexactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Inexact#(v2, e),
76 },
77 Selfrust-analyzer cargo dashu-base 0.4.1 approx/impl#[`Approximation<T, E>`]::Inexactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Inexact#(v, e) => match f(v) {
78 Approximationrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#::Exactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Exact#(v2) => Approximationrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#::Inexactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Inexact#(v2, e),
79 Approximationrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#::Inexactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Inexact#(v2, e2) => Approximationrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#::Inexactrust-analyzer cargo dashu-base 0.4.1 approx/Approximation#Inexact#(v2, e2),
80 },
81 }
82 }
83 }