Struct drv8825::embedded_time::rate::Fraction [−][src]
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) -> Fraction
[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<Fraction, ConversionError>
[src]
numerator: u32,
denominator: u32
) -> Result<Fraction, ConversionError>
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) -> Fraction
[src]
Constructs a Fraction
from an integer.
Equivalent to Fraction::new(value,1)
.
pub fn recip(self) -> Fraction
[src]
Returns the reciprocal of the fraction
pub fn checked_mul(&self, v: &Fraction) -> Option<Fraction>
[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: &Fraction) -> Option<Fraction>
[src]
Trait Implementations
impl Clone for Fraction
[src]
pub fn clone(&self) -> Fraction
[src]
pub fn clone_from(&mut self, source: &Self)
1.0.0[src]
impl Copy for Fraction
[src]
impl Debug for Fraction
[src]
impl Default for Fraction
[src]
impl Div<Fraction> for Fraction
[src]
type Output = Fraction
The resulting type after applying the /
operator.
pub fn div(self, rhs: Fraction) -> <Fraction as Div<Fraction>>::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]
pub fn hash<__H>(&self, state: &mut __H) where
__H: Hasher,
[src]
__H: Hasher,
pub fn hash_slice<H>(data: &[Self], state: &mut H) where
H: Hasher,
1.3.0[src]
H: Hasher,
impl Mul<Fraction> for Fraction
[src]
type Output = Fraction
The resulting type after applying the *
operator.
pub fn mul(self, rhs: Fraction) -> <Fraction as Mul<Fraction>>::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]
pub fn cmp(&self, other: &Fraction) -> Ordering
[src]
#[must_use]pub fn max(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn min(self, other: Self) -> Self
1.21.0[src]
#[must_use]pub fn clamp(self, min: Self, max: Self) -> Self
1.50.0[src]
impl PartialEq<Fraction> for Fraction
[src]
impl PartialOrd<Fraction> for Fraction
[src]
pub fn partial_cmp(&self, other: &Fraction) -> Option<Ordering>
[src]
#[must_use]pub fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]pub fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl StructuralEq for Fraction
[src]
impl StructuralPartialEq for Fraction
[src]
Auto Trait Implementations
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Az for T
[src]
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
pub fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> CheckedAs for T
[src]
pub fn checked_as<Dst>(self) -> Option<Dst> where
T: CheckedCast<Dst>,
[src]
T: CheckedCast<Dst>,
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
impl<Src, Dst> LosslessTryInto<Dst> for Src where
Dst: LosslessTryFrom<Src>,
[src]
Dst: LosslessTryFrom<Src>,
pub fn lossless_try_into(self) -> Option<Dst>
[src]
impl<Src, Dst> LossyInto<Dst> for Src where
Dst: LossyFrom<Src>,
[src]
Dst: LossyFrom<Src>,
pub fn lossy_into(self) -> Dst
[src]
impl<T> OverflowingAs for T
[src]
pub fn overflowing_as<Dst>(self) -> (Dst, bool) where
T: OverflowingCast<Dst>,
[src]
T: OverflowingCast<Dst>,
impl<T> Same<T> for T
type Output = T
Should always be Self
impl<T> SaturatingAs for T
[src]
pub fn saturating_as<Dst>(self) -> Dst where
T: SaturatingCast<Dst>,
[src]
T: SaturatingCast<Dst>,
impl<T, U> TryFrom<U> for T where
U: Into<T>,
[src]
U: Into<T>,
type Error = Infallible
The type returned in the event of a conversion error.
pub fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>
[src]
impl<T, U> TryInto<U> for T where
U: TryFrom<T>,
[src]
U: TryFrom<T>,
type Error = <U as TryFrom<T>>::Error
The type returned in the event of a conversion error.
pub fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>
[src]
impl<T> UnwrappedAs for T
[src]
pub fn unwrapped_as<Dst>(self) -> Dst where
T: UnwrappedCast<Dst>,
[src]
T: UnwrappedCast<Dst>,
impl<T> WrappingAs for T
[src]
pub fn wrapping_as<Dst>(self) -> Dst where
T: WrappingCast<Dst>,
[src]
T: WrappingCast<Dst>,