Struct embedded_time::fraction::Fraction[][src]

pub struct Fraction(_);
Expand description

A fractional value

Used primarily to define the scaling factor for the Duration, Rate, Instant and Clock traits and types.

Implementations

Construct a new Fraction.

A reduction is not performed. Also there is no check for a denominator of 0. If these features are needed, use Fraction::new_reduce()

Return the numerator of the fraction

Return the denominator of the fraction

Construct a new Fraction.

A reduction and denominator == 0 check are performed.

Errors

ConversionError::DivByZero : A 0 denominator was detected

Returns the value truncated to an integer

Constructs a Fraction from an integer.

Equivalent to Fraction::new(value,1).

Returns the reciprocal of the fraction

Checked Fraction × Fraction = Fraction

Returns None for any errors

Examples

assert_eq!(Fraction::new(1000, 1).checked_mul(&Fraction::new(5,5)),
    Some(Fraction::new(5_000, 5)));

assert_eq!(Fraction::new(u32::MAX, 1).checked_mul(&Fraction::new(2,1)),
    None);

Checked Fraction / Fraction = Fraction

Returns None for any errors

Examples

assert_eq!(Fraction::new(1000, 1).checked_div(&Fraction::new(10, 1000)),
    Some(Fraction::new(1_000_000, 10)));

assert_eq!(Fraction::new(1, u32::MAX).checked_div(&Fraction::new(2,1)),
    None);

Trait Implementations

Returns a copy of the value. Read more

Performs copy-assignment from source. Read more

Formats the value using the given formatter. Read more

Returns the “default value” for a type. Read more

Panicky u32 / Fraction = u32

The resulting type after applying the / operator.

Panicky u64 / Fraction = u64

The resulting type after applying the / operator.

Panicky Fraction / Fraction = Fraction

Panics

The same reason the integer operation would panic. Namely, if the result overflows the type.

The resulting type after applying the / operator.

Feeds this value into the given Hasher. Read more

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

Panicky u32 × Fraction = u32

The resulting type after applying the * operator.

Panicky u64 × Fraction = u64

The resulting type after applying the * operator.

Panicky Fraction × Fraction = Fraction

Panics

The same reason the integer operation would panic. Namely, if the result overflows the type.

The resulting type after applying the * operator.

This method returns an Ordering between self and other. Read more

Compares and returns the maximum of two values. Read more

Compares and returns the minimum of two values. Read more

Restrict a value to a certain interval. Read more

This method tests for self and other values to be equal, and is used by ==. Read more

This method tests for !=.

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

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more

Auto Trait Implementations

Blanket Implementations

Gets the TypeId of self. Read more

Immutably borrows from an owned value. Read more

Mutably borrows from an owned value. Read more

Performs the conversion.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.

The type returned in the event of a conversion error.

Performs the conversion.