Number

Enum Number 

Source
pub enum Number {
Show 14 variants F32(f32), F64(f64), I128(i128), I16(i16), I32(i32), I64(i64), I8(i8), Isize(isize), U128(u128), U16(u16), U32(u32), U64(u64), U8(u8), Usize(usize),
}
Expand description

Represents a generic number that maintains an internal Rust representation of the actual number

Variants§

§

F32(f32)

§

F64(f64)

§

I128(i128)

§

I16(i16)

§

I32(i32)

§

I64(i64)

§

I8(i8)

§

Isize(isize)

§

U128(u128)

§

U16(u16)

§

U32(u32)

§

U64(u64)

§

U8(u8)

§

Usize(usize)

Implementations§

Source§

impl Number

Source

pub fn sign(&self) -> NumberSign

Returns an indicator of the sign (negative, zero, positive) of this number

use entity::{Number, NumberSign};

assert_eq!(Number::from(0).sign(), NumberSign::Zero);
assert_eq!(Number::from(99).sign(), NumberSign::Positive);
assert_eq!(Number::from(-99).sign(), NumberSign::Negative);
Source

pub fn is_zero(&self) -> bool

Returns true if number is zero (not negative or positive)

use entity::Number;

assert!(Number::from(0).is_zero());
assert!(!Number::from(1).is_zero());
assert!(!Number::from(-1).is_zero());
Source

pub fn is_positive(&self) -> bool

Returns true if number is positive (not zero or negative)

§Examples
use entity::Number;

assert!(Number::from(1).is_positive());
assert!(!Number::from(0).is_positive());
assert!(!Number::from(-1).is_positive());
Source

pub fn is_negative(&self) -> bool

Returns true if number is negative (not zero or positive)

§Examples
use entity::Number;

assert!(Number::from(-1).is_negative());
assert!(!Number::from(0).is_negative());
assert!(!Number::from(1).is_negative());
Source

pub fn is_signed(&self) -> bool

Returns true if number is a signed integer

§Examples
use entity::Number;

assert!(Number::from(3isize).is_signed());
assert!(!Number::from(3usize).is_signed());
Source

pub fn is_unsigned(&self) -> bool

Returns true if number is an unsigned integer

§Examples
use entity::Number;

assert!(Number::from(3usize).is_unsigned());
assert!(!Number::from(3isize).is_unsigned());
Source

pub fn is_float(&self) -> bool

Returns true if number is a float

§Examples
use entity::Number;

assert!(Number::from(3f32).is_float());
assert!(!Number::from(3usize).is_float());
Source

pub fn has_nonzero_fraction(&self) -> bool

Returns true if number is a float with a non-zero fractional part

§Examples
use entity::Number;

assert!(Number::from(3.1).has_nonzero_fraction());
assert!(!Number::from(3.0).has_nonzero_fraction());
Source

pub fn is_normal(&self) -> bool

Returns true if number is neither zero, infinite, subnormal, or NaN

§Examples
use entity::Number;

assert!(Number::from(1).is_normal());
assert!(Number::from(0.1).is_normal());
assert!(!Number::from(0).is_normal());
assert!(!Number::from(f64::NAN).is_normal());
assert!(!Number::from(f64::INFINITY).is_normal());
assert!(!Number::from(f64::NEG_INFINITY).is_normal());
assert!(!Number::from(1.0e-308_f64).is_normal());
Source

pub fn to_absolute(&self) -> Self

Returns a conversion of the underlying number to an absolute version of itself

Source

pub fn to_f64(&self) -> f64

Naive casting of number’s inner representation to f64by performing x as f64

Source

pub fn to_f32(&self) -> f32

Naive casting of number’s inner representation to f32by performing x as f32

Source

pub fn to_isize(&self) -> isize

Naive casting of number’s inner representation to isizeby performing x as isize

Source

pub fn to_i128(&self) -> i128

Naive casting of number’s inner representation to i128by performing x as i128

Source

pub fn to_i64(&self) -> i64

Naive casting of number’s inner representation to i64by performing x as i64

Source

pub fn to_i32(&self) -> i32

Naive casting of number’s inner representation to i32by performing x as i32

Source

pub fn to_i16(&self) -> i16

Naive casting of number’s inner representation to i16by performing x as i16

Source

pub fn to_i8(&self) -> i8

Naive casting of number’s inner representation to i8by performing x as i8

Source

pub fn to_usize(&self) -> usize

Naive casting of number’s inner representation to usizeby performing x as usize

Source

pub fn to_u128(&self) -> u128

Naive casting of number’s inner representation to u128by performing x as u128

Source

pub fn to_u64(&self) -> u64

Naive casting of number’s inner representation to u64by performing x as u64

Source

pub fn to_u32(&self) -> u32

Naive casting of number’s inner representation to u32by performing x as u32

Source

pub fn to_u16(&self) -> u16

Naive casting of number’s inner representation to u16by performing x as u16

Source

pub fn to_u8(&self) -> u8

Naive casting of number’s inner representation to u8by performing x as u8

Source

pub fn to_type(&self) -> NumberType

Converts into type of number

Trait Implementations§

Source§

impl Clone for Number

Source§

fn clone(&self) -> Number

Returns a duplicate 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 Debug for Number

Source§

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

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

impl<'_enum> From<&'_enum Number> for NumberType

Source§

fn from(val: &'_enum Number) -> NumberType

Converts to this type from the input type.
Source§

impl From<Number> for NumberType

Source§

fn from(val: Number) -> NumberType

Converts to this type from the input type.
Source§

impl From<f32> for Number

Source§

fn from(original: f32) -> Number

Converts to this type from the input type.
Source§

impl From<f64> for Number

Source§

fn from(original: f64) -> Number

Converts to this type from the input type.
Source§

impl From<i128> for Number

Source§

fn from(original: i128) -> Number

Converts to this type from the input type.
Source§

impl From<i16> for Number

Source§

fn from(original: i16) -> Number

Converts to this type from the input type.
Source§

impl From<i32> for Number

Source§

fn from(original: i32) -> Number

Converts to this type from the input type.
Source§

impl From<i64> for Number

Source§

fn from(original: i64) -> Number

Converts to this type from the input type.
Source§

impl From<i8> for Number

Source§

fn from(original: i8) -> Number

Converts to this type from the input type.
Source§

impl From<isize> for Number

Source§

fn from(original: isize) -> Number

Converts to this type from the input type.
Source§

impl From<u128> for Number

Source§

fn from(original: u128) -> Number

Converts to this type from the input type.
Source§

impl From<u16> for Number

Source§

fn from(original: u16) -> Number

Converts to this type from the input type.
Source§

impl From<u32> for Number

Source§

fn from(original: u32) -> Number

Converts to this type from the input type.
Source§

impl From<u64> for Number

Source§

fn from(original: u64) -> Number

Converts to this type from the input type.
Source§

impl From<u8> for Number

Source§

fn from(original: u8) -> Number

Converts to this type from the input type.
Source§

impl From<usize> for Number

Source§

fn from(original: usize) -> Number

Converts to this type from the input type.
Source§

impl Hash for Number

Source§

fn hash<H: Hasher>(&self, state: &mut H)

Feeds this value into the given Hasher. Read more
1.3.0 · Source§

fn hash_slice<H>(data: &[Self], state: &mut H)
where H: Hasher, Self: Sized,

Feeds a slice of this type into the given Hasher. Read more
Source§

impl NumberLike for Number

Source§

fn into_number(self) -> Number

Consumes this data, converting it into an abstract Number
Source§

fn try_from_number(number: Number) -> Result<Self, Number>

Attempts to convert an abstract Number into this data, returning the owned value back if unable to convert
Source§

impl PartialEq for Number

Source§

fn eq(&self, other: &Self) -> bool

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

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 PartialOrd for Number

Source§

fn partial_cmp(&self, other: &Self) -> Option<Ordering>

Compares two numbers if possible. If either number is not zero and not normal as defined by Rust’s specification, None is returned.

self signother signsituation
negativenegativedoes comparison (less/equal/greater)
negativepositiveless than
negativezeroless than
positivenegativegreater than
positivepositivedoes comparison (less/equal/greater)
positivezerogreater than
zeronegativegreater than
zeropositiveless than
zerozeroequal
1.0.0 · Source§

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

Tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · Source§

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

Tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · Source§

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

Tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · Source§

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

Tests greater than or equal to (for self and other) and is used by the >= operator. Read more
Source§

impl Copy for Number

Source§

impl Eq for Number

Auto Trait Implementations§

§

impl Freeze for Number

§

impl RefUnwindSafe for Number

§

impl Send for Number

§

impl Sync for Number

§

impl Unpin for Number

§

impl UnwindSafe for Number

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> AsAny for T
where T: 'static,

Source§

fn as_any(&self) -> &(dyn Any + 'static)

Converts reference to Any
Source§

fn as_mut_any(&mut self) -> &mut (dyn Any + 'static)

converts mutable reference to Any
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> DynClone for T
where T: Clone,

Source§

fn __clone_box(&self, _: Private) -> *mut ()

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> PrimitiveLike for T
where T: NumberLike,

Source§

fn into_primitive(self) -> Primitive

Consumes this data, converting it into an abstract Primitive
Source§

fn try_from_primitive(primitive: Primitive) -> Result<T, Primitive>

Attempts to convert an abstract Primitive into this data, returning the owned value back if unable to convert
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, 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.
Source§

impl<T> ValueLike for T
where T: PrimitiveLike,

Source§

fn into_value(self) -> Value

Consumes this data, converting it into an abstract Value
Source§

fn try_from_value(value: Value) -> Result<T, Value>

Attempts to convert an abstract Value into this data, returning the owned value back if unable to convert