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

pub struct Fraction(_);

A fractional value

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

Implementations

impl Fraction[src]

pub const fn new(numerator: u32, denominator: u32) -> Self[src]

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

pub const fn numerator(&self) -> &u32[src]

Return the numerator of the fraction

pub const fn denominator(&self) -> &u32[src]

Return the denominator of the fraction

impl Fraction[src]

pub fn new_reduce(
    numerator: u32,
    denominator: u32
) -> Result<Self, ConversionError>
[src]

Construct a new Fraction.

A reduction and denominator == 0 check are performed.

Errors

ConversionError::DivByZero : A 0 denominator was detected

pub fn to_integer(&self) -> u32[src]

Returns the value truncated to an integer

pub fn from_integer(value: u32) -> Self[src]

Constructs a Fraction from an integer.

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

pub fn recip(self) -> Self[src]

Returns the reciprocal of the fraction

pub fn checked_mul(&self, v: &Self) -> Option<Self>[src]

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

pub fn checked_div(&self, v: &Self) -> Option<Self>[src]

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

impl Clone for Fraction[src]

impl Copy for Fraction[src]

impl Debug for Fraction[src]

impl Default for Fraction[src]

impl Div<Fraction> for u32[src]

type Output = Self

The resulting type after applying the / operator.

fn div(self, rhs: Fraction) -> Self::Output[src]

Panicky u32 / Fraction = u32

impl Div<Fraction> for u64[src]

type Output = Self

The resulting type after applying the / operator.

fn div(self, rhs: Fraction) -> Self::Output[src]

Panicky u64 / Fraction = u64

impl Div<Fraction> for Fraction[src]

type Output = Self

The resulting type after applying the / operator.

fn div(self, rhs: Self) -> Self::Output[src]

Panicky Fraction / Fraction = Fraction

Panics

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

impl Eq for Fraction[src]

impl Hash for Fraction[src]

impl Mul<Fraction> for u32[src]

type Output = Self

The resulting type after applying the * operator.

fn mul(self, rhs: Fraction) -> Self::Output[src]

Panicky u32 × Fraction = u32

impl Mul<Fraction> for u64[src]

type Output = Self

The resulting type after applying the * operator.

fn mul(self, rhs: Fraction) -> Self::Output[src]

Panicky u64 × Fraction = u64

impl Mul<Fraction> for Fraction[src]

type Output = Self

The resulting type after applying the * operator.

fn mul(self, rhs: Self) -> Self::Output[src]

Panicky Fraction × Fraction = Fraction

Panics

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

impl Ord for Fraction[src]

impl PartialEq<Fraction> for Fraction[src]

impl PartialOrd<Fraction> for Fraction[src]

impl StructuralEq for Fraction[src]

impl StructuralPartialEq for Fraction[src]

Auto Trait Implementations

impl Send for Fraction

impl Sync for Fraction

impl Unpin for Fraction

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> From<T> for T[src]

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

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.