Enum number_theory::NTResult
source · #[non_exhaustive]pub enum NTResult<T: Sized + Clone> {
Eval(T),
Overflow,
DNE,
Infinite,
InfiniteSet,
CompExceeded,
CompOverflow,
Undefined,
}
Expand description
Enum returned in checked functions returning any errors of evaluation
Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
Eval(T)
Evaluation is knowable and was calculated in the bounds. FFI return 0
Overflow
Solution Exists but does not fit in datatype. FFI return 1
DNE
Solution Does Not Exist. FFI return 2
Infinite
Solution Exists but is Infinitely large. FFI return 3
InfiniteSet
Solutions exist but there are infinite number of them (all elements of Z). FFI return 4
CompExceeded
Computation exceeds some practical bound. FFI return 5
CompOverflow
Overflowed during computation result does not necessarily exceed the datatype. FFI return 6
Undefined
Function is not defined for the inputs. FFI return 7
Implementations§
source§impl<T: Sized + Clone + Default> NTResult<T>
impl<T: Sized + Clone + Default> NTResult<T>
sourcepub fn is_infinite(&self) -> bool
pub fn is_infinite(&self) -> bool
Checks if the result is infinitely large
sourcepub fn is_infiniteset(&self) -> bool
pub fn is_infiniteset(&self) -> bool
Checks if the result is an infinite set
sourcepub fn is_overflow(&self) -> bool
pub fn is_overflow(&self) -> bool
Checks if the result exceeds the datatype max
sourcepub fn is_comp_overflow(&self) -> bool
pub fn is_comp_overflow(&self) -> bool
Checks if there was an overflow during computation
sourcepub fn is_comp_exceeded(&self) -> bool
pub fn is_comp_exceeded(&self) -> bool
Checks if the Computation exceeded
sourcepub fn is_undefined(&self) -> bool
pub fn is_undefined(&self) -> bool
Checks if the result is undefined
sourcepub fn from_option(opt: Option<T>, ntvariant: Self) -> Self
pub fn from_option(opt: Option<T>, ntvariant: Self) -> Self
Converts from Option to NTResult. None values are converted to the selected NTResult variant
use number_theory::NumberTheory;
use number_theory::NTResult;
// A None is returned here due to exceeding the i8::MAX
let res = 255u8.checked_add(1);
// The None option is converted to an NTResult::Overflow
let convert = NTResult::from_option(res,NTResult::Overflow);
assert_eq!(convert, NTResult::Overflow);
// An Some result is converted to Eval
let res = 254u8.checked_add(1);
let convert = NTResult::from_option(res,NTResult::Overflow);
assert_eq!(convert, NTResult::Eval(255));
sourcepub fn ffi(&self) -> (T, u8)
pub fn ffi(&self) -> (T, u8)
Return value and flag for FFI bindings
use number_theory::NumberTheory;
// Attempt to factor 0
let res = 0.checked_factor();
// Fails and returns a NTResult that can be decomposed to an empty vec
// and 4 for C api binding
assert_eq!(res.ffi(),(vec![],4));
let res = 1.checked_factor();
// Likewise an DNE NTResult gets converted to a vec and 2
assert_eq!(res.ffi(), (vec![],2));
let res = 9.checked_factor();
// Finally a fully factorable integer gets a vector and the 0 flag
assert_eq!(res.ffi(),(vec![3,2],0))