pub struct Numeric {
pub value: Number,
pub unit: UnitSet,
}
Fields§
§value: Number
The number value of this numeric.
unit: UnitSet
The unit of this numeric.
Implementations§
source§impl Numeric
impl Numeric
sourcepub fn as_unit(&self, unit: Unit) -> Option<Number>
pub fn as_unit(&self, unit: Unit) -> Option<Number>
Convert this numeric value to a given unit, if possible.
Examples
let inch = Numeric::new(1, Unit::In);
assert_eq!(inch.as_unit(Unit::Mm).unwrap() * 5, 127.into());
assert_eq!(inch.as_unit(Unit::Deg), None);
sourcepub fn as_unitset(&self, unit: &UnitSet) -> Option<Number>
pub fn as_unitset(&self, unit: &UnitSet) -> Option<Number>
Convert this numeric value to a given unit, if possible.
Examples
let inch = Numeric::new(1, Unit::In);
assert_eq!(inch.as_unit(Unit::Mm).unwrap() * 5, 127.into());
assert_eq!(inch.as_unit(Unit::Deg), None);
sourcepub fn as_unit_def(&self, unit: Unit) -> Option<Number>
pub fn as_unit_def(&self, unit: Unit) -> Option<Number>
Convert this numeric value to a given unit, if possible.
Like as_unit
, except a unitless numeric is
considered to be the expected unit.
sourcepub fn as_ratio(&self) -> Result<Rational, BadNumber>
pub fn as_ratio(&self) -> Result<Rational, BadNumber>
Get this number as a rational number.
The unit is ignored. If the value is bignum rational or floating point, it is approximated as long as it is withing range, otherwises an error is returned.
sourcepub fn is_no_unit(&self) -> bool
pub fn is_no_unit(&self) -> bool
Return true if this value has no unit.
Trait Implementations§
source§impl PartialEq for Numeric
impl PartialEq for Numeric
source§impl PartialOrd for Numeric
impl PartialOrd for Numeric
1.0.0 · source§fn le(&self, other: &Rhs) -> bool
fn le(&self, other: &Rhs) -> bool
This method tests less than or equal to (for
self
and other
) and is used by the <=
operator. Read moreimpl Eq for Numeric
impl StructuralEq for Numeric
Auto Trait Implementations§
impl RefUnwindSafe for Numeric
impl Send for Numeric
impl Sync for Numeric
impl Unpin for Numeric
impl UnwindSafe for Numeric
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
Mutably borrows from an owned value. Read more