Enum ron::value::Number [−][src]
Expand description
A wrapper for a number, which can be either f64
or i64
.
Variants
Integer(i64)
Tuple Fields of Integer
0: i64
Float(Float)
Tuple Fields of Float
0: Float
Implementations
Returns the f64
representation of the number regardless of whether the number is stored
as a float or integer.
Example
let i = Number::new(5);
let f = Number::new(2.0);
assert_eq!(i.into_f64(), 5.0);
assert_eq!(f.into_f64(), 2.0);
If the Number
is a float, return it. Otherwise return None
.
Example
let i = Number::new(5);
let f = Number::new(2.0);
assert_eq!(i.as_f64(), None);
assert_eq!(f.as_f64(), Some(2.0));
If the Number
is an integer, return it. Otherwise return None
.
Example
let i = Number::new(5);
let f = Number::new(2.0);
assert_eq!(i.as_i64(), Some(5));
assert_eq!(f.as_i64(), None);
Map this number to a single type using the appropriate closure.
Example
let i = Number::new(5);
let f = Number::new(2.0);
assert!(i.map_to(|i| i > 3, |f| f > 3.0));
assert!(!f.map_to(|i| i > 3, |f| f > 3.0));
Trait Implementations
This method returns an ordering between self
and other
values if one exists. Read more
This method tests less than (for self
and other
) and is used by the <
operator. Read more
This method tests less than or equal to (for self
and other
) and is used by the <=
operator. Read more
This method tests greater than (for self
and other
) and is used by the >
operator. Read more
Auto Trait Implementations
impl RefUnwindSafe for Number
impl UnwindSafe for Number
Blanket Implementations
Mutably borrows from an owned value. Read more