#[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
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

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>

source

pub fn unwrap(&self) -> T

Returns the Evaluated number

source

pub fn expect(&self, signal: &str) -> T

Returns the result or panics with the selected message

source

pub fn unwrap_or(&self, res: T) -> T

Returns the result or the selected default

source

pub fn is_infinite(&self) -> bool

Checks if the result is infinitely large

source

pub fn is_infiniteset(&self) -> bool

Checks if the result is an infinite set

source

pub fn is_dne(&self) -> bool

Checks if the solution to the function exists

source

pub fn is_overflow(&self) -> bool

Checks if the result exceeds the datatype max

source

pub fn is_comp_overflow(&self) -> bool

Checks if there was an overflow during computation

source

pub fn is_comp_exceeded(&self) -> bool

Checks if the Computation exceeded

source

pub fn is_undefined(&self) -> bool

Checks if the result is undefined

source

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));
source

pub fn map<U: Clone, F: FnOnce(T) -> U>(&self, func: F) -> NTResult<U>

Maps within the Enum

source

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))

Trait Implementations§

source§

impl<T: Clone + Sized + Clone> Clone for NTResult<T>

source§

fn clone(&self) -> NTResult<T>

Returns a copy of the value. Read more
1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T: Debug + Sized + Clone> Debug for NTResult<T>

source§

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

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

impl<T: Clone + Default + Sized + Display> Display for NTResult<T>

source§

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

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

impl<T: PartialEq + Sized + Clone> PartialEq for NTResult<T>

source§

fn eq(&self, other: &NTResult<T>) -> bool

This method tests for self and other values to be equal, and is used by ==.
1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T: Eq + Sized + Clone> Eq for NTResult<T>

source§

impl<T: Sized + Clone> StructuralEq for NTResult<T>

source§

impl<T: Sized + Clone> StructuralPartialEq for NTResult<T>

Auto Trait Implementations§

§

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

§

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

§

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

§

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

§

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

§

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§

default 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>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

§

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.