Enum 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
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.factor();
  // Fails and returns a NTResult  
  // and 4 for C api binding
 assert_eq!(res.ffi().1,4);
   
  let res = 1.factor(); 
  // Likewise an DNE NTResult gets converted to a vec and 2
  assert_eq!(res.ffi().1,2);
   
  let res = 9.factor();
  // Finally a fully factorable integer gets a vector and the 0 flag
  assert_eq!(res.ffi().1,0);

Trait Implementations§

Source§

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

Source§

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

Returns a duplicate of the value. Read more
1.0.0 · Source§

const 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

Tests for self and other values to be equal, and is used by ==.
1.0.0 · Source§

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

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> StructuralPartialEq for NTResult<T>

Auto Trait Implementations§

§

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

§

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

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.