Struct rsass::value::Numeric[][src]

pub struct Numeric {
    pub value: Number,
    pub unit: UnitSet,
}

A Numeric value is a Number with a Unit (which may be Unit::None).

Fields

value: Number

The number value of this numeric.

unit: UnitSet

The unit of this numeric.

Implementations

impl Numeric[src]

pub fn new<V: Into<Number>, U: Into<UnitSet>>(value: V, unit: U) -> Self[src]

Create a new numeric value.

The value can be given as anything that can be converted into a Number, e.g. an isize, a Rational, or a f64.

pub fn scalar(value: impl Into<Number>) -> Numeric[src]

Create a new numeric value with no unit.

pub fn as_unit(&self, unit: Unit) -> Option<Number>[src]

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);

pub fn as_unitset(&self, unit: &UnitSet) -> Option<Number>[src]

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);

pub fn as_unit_def(&self, unit: Unit) -> Option<Number>[src]

Convert this numeric value to a given unit, if possible.

Like as_unit, except a unitless numeric is considered to be the expected unit.

pub fn as_ratio(&self) -> Result<Rational, Error>[src]

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.

pub fn is_no_unit(&self) -> bool[src]

Return true if this value has no unit.

pub fn format(&self, format: Format) -> Formatted<'_, Numeric>[src]

Get a reference to this Value bound to an output format.

Trait Implementations

impl Clone for Numeric[src]

impl Debug for Numeric[src]

impl Div<&'_ Numeric> for &Numeric[src]

type Output = Numeric

The resulting type after applying the / operator.

impl Eq for Numeric[src]

impl From<Numeric> for Value[src]

impl Mul<&'_ Numeric> for &Numeric[src]

type Output = Numeric

The resulting type after applying the * operator.

impl Neg for &Numeric[src]

type Output = Numeric

The resulting type after applying the - operator.

impl PartialEq<Numeric> for Numeric[src]

impl PartialOrd<Numeric> for Numeric[src]

impl StructuralEq for Numeric[src]

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

impl<T> Any for T where
    T: 'static + ?Sized
[src]

impl<T> Borrow<T> for T where
    T: ?Sized
[src]

impl<T> BorrowMut<T> for T where
    T: ?Sized
[src]

impl<T> Conv for T

impl<T> Conv for T

impl<T> FmtForward for T

impl<T> From<T> for T[src]

impl<T, U> Into<U> for T where
    U: From<T>, 
[src]

impl<T> Pipe for T where
    T: ?Sized

impl<T> Pipe for T

impl<T> PipeAsRef for T

impl<T> PipeBorrow for T

impl<T> PipeDeref for T

impl<T> PipeRef for T

impl<T> Tap for T

impl<T> Tap for T

impl<T, U> TapAsRef<U> for T where
    U: ?Sized

impl<T, U> TapBorrow<U> for T where
    U: ?Sized

impl<T> TapDeref for T

impl<T> ToOwned for T where
    T: Clone
[src]

type Owned = T

The resulting type after obtaining ownership.

impl<T> TryConv for T

impl<T> TryConv for T

impl<T, U> TryFrom<U> for T where
    U: Into<T>, 
[src]

type Error = Infallible

The type returned in the event of a conversion error.

impl<T, U> TryInto<U> for T where
    U: TryFrom<T>, 
[src]

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.

impl<V, T> VZip<V> for T where
    V: MultiLane<T>,