Enum Number
pub enum Number {
Integer(i64),
Float(f64),
}Expand description
Represents a YAML number.
Variants§
Implementations§
§impl Number
impl Number
pub fn as_i64(&self) -> Option<i64>
pub fn as_i64(&self) -> Option<i64>
Returns the number as an i64 if it is an integer.
Floats return None even when their value happens to be a
whole number; the type tag is part of the test.
§Examples
use noyalib::Number;
assert_eq!(Number::Integer(42).as_i64(), Some(42));
assert_eq!(Number::Float(1.0).as_i64(), None);pub fn as_u64(&self) -> Option<u64>
pub fn as_u64(&self) -> Option<u64>
Returns the number as a u64 if it is a non-negative integer.
Negative integers and floats return None.
§Examples
use noyalib::Number;
assert_eq!(Number::Integer(42).as_u64(), Some(42));
assert_eq!(Number::Integer(-1).as_u64(), None);
assert_eq!(Number::Float(1.0).as_u64(), None);pub fn as_f64(&self) -> f64
pub fn as_f64(&self) -> f64
Returns the number as an f64.
Always succeeds — integers are widened to f64 (with the
usual i64 → f64 precision loss for magnitudes above
2^53), floats pass through unchanged.
§Examples
use noyalib::Number;
assert_eq!(Number::Integer(42).as_f64(), 42.0);
assert_eq!(Number::Float(0.5).as_f64(), 0.5);pub fn is_integer(&self) -> bool
pub fn is_integer(&self) -> bool
Returns true if the number is an integer.
§Examples
use noyalib::Number;
assert!(Number::Integer(42).is_integer());
assert!(!Number::Float(1.0).is_integer());pub fn is_float(&self) -> bool
pub fn is_float(&self) -> bool
Returns true if the number is a float.
§Examples
use noyalib::Number;
assert!(Number::Float(1.0).is_float());
assert!(!Number::Integer(42).is_float());pub fn is_i64(&self) -> bool
pub fn is_i64(&self) -> bool
Returns true if the number can be represented as an i64.
True for all integer values, false for floats.
§Examples
use noyalib::Number;
assert!(Number::Integer(42).is_i64());
assert!(!Number::Float(42.0).is_i64());pub fn is_u64(&self) -> bool
pub fn is_u64(&self) -> bool
Returns true if the number can be represented as a u64.
True for non-negative integers, false otherwise.
§Examples
use noyalib::Number;
assert!(Number::Integer(42).is_u64());
assert!(!Number::Integer(-1).is_u64());
assert!(!Number::Float(1.0).is_u64());pub fn is_f64(&self) -> bool
pub fn is_f64(&self) -> bool
Returns true if the number can be represented as an f64.
Always true — both integers and floats convert to f64
(with the usual precision caveats for very large
integers).
§Examples
use noyalib::Number;
assert!(Number::Integer(42).is_f64());
assert!(Number::Float(1.0).is_f64());pub fn is_nan(&self) -> bool
pub fn is_nan(&self) -> bool
Returns true if the number is NaN (Not a Number).
Integers are never NaN — only floats with the IEEE 754
NaN bit pattern.
§Examples
use noyalib::Number;
assert!(Number::Float(f64::NAN).is_nan());
assert!(!Number::Float(0.0).is_nan());
assert!(!Number::Integer(0).is_nan());pub fn is_infinite(&self) -> bool
pub fn is_infinite(&self) -> bool
Returns true if the number is positive or negative infinity.
Integers are always finite — only Number::Float(±inf)
returns true.
§Examples
use noyalib::Number;
assert!(Number::Float(f64::INFINITY).is_infinite());
assert!(Number::Float(f64::NEG_INFINITY).is_infinite());
assert!(!Number::Integer(i64::MAX).is_infinite());pub fn is_finite(&self) -> bool
pub fn is_finite(&self) -> bool
Returns true if the number is neither infinite nor NaN.
Integers are always finite; floats are finite when neither
±∞ nor NaN.
§Examples
use noyalib::Number;
assert!(Number::Integer(0).is_finite());
assert!(Number::Float(0.5).is_finite());
assert!(!Number::Float(f64::NAN).is_finite());
assert!(!Number::Float(f64::INFINITY).is_finite());Trait Implementations§
§impl Ord for Number
impl Ord for Number
§impl PartialOrd for Number
impl PartialOrd for Number
impl Copy for Number
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 UnsafeUnpin for Number
impl UnwindSafe for Number
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
§impl<Q, K> Comparable<K> for Q
impl<Q, K> Comparable<K> for Q
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
§impl<Q, K> Equivalent<K> for Q
impl<Q, K> Equivalent<K> for Q
§fn equivalent(&self, key: &K) -> bool
fn equivalent(&self, key: &K) -> bool
key and return true if they are equal.