[−][src]Struct embedded_time::Period
A fractional time period
Used primarily to define the period of one count of a Duration
, Instant
and Clock
impl types but also convertible to/from Hertz
.
The default inner type is u32
.
Implementations
impl<T> Period<T>
[src]
pub const fn new(numerator: T, denominator: T) -> Self
[src]
Construct a new fractional Period
.
A reduction is not performed. If reduction is needed, use Period::new_reduce()
pub const fn numerator(&self) -> &T
[src]
Return the numerator of the fraction
pub const fn denominator(&self) -> &T
[src]
Return the denominator of the fraction
impl<T: TimeInt> Period<T>
[src]
pub fn new_reduce(numerator: T, denominator: T) -> Result<Self, ConversionError>
[src]
Construct a new fractional Period
.
A reduction is performed.
Errors
ConversionError::DivByZero
: A 0
denominator was detected
pub fn to_integer(&self) -> T
[src]
Returns the value truncated to an integer
pub fn from_integer(value: T) -> Self
[src]
Constructs a Period
from an integer.
Equivalent to Period::new(value,1)
.
pub fn recip(self) -> Self
[src]
Returns the reciprocal of the fraction
pub fn checked_mul(&self, v: &Self) -> Result<Self, ConversionError>
[src]
Checked Period
* Period
= Period
Examples
assert_eq!(<Period>::new(1000, 1).checked_mul(&<Period>::new(5,5)), Ok(<Period>::new(5_000, 5))); assert_eq!(<Period>::new(u32::MAX, 1).checked_mul(&<Period>::new(2,1)), Err(ConversionError::Overflow));
Errors
pub fn checked_div(&self, v: &Self) -> Result<Self, ConversionError>
[src]
Checked Period
/ Period
= Period
Examples
assert_eq!(<Period>::new(1000, 1).checked_div(&<Period>::new(10, 1000)), Ok(<Period>::new(1_000_000, 10))); assert_eq!(<Period>::new(1, u32::MAX).checked_div(&<Period>::new(2,1)), Err(ConversionError::Overflow));
Errors
pub fn checked_mul_integer(
&self,
multiplier: T
) -> Result<Self, ConversionError>
[src]
&self,
multiplier: T
) -> Result<Self, ConversionError>
Checked Period
* integer = Period
Examples
assert_eq!(<Period>::new(1000, 1).checked_mul_integer(5_u32), Ok(<Period>::new(5_000, 1))); assert_eq!(<Period>::new(u32::MAX, 1).checked_mul_integer(2_u32), Err(ConversionError::Overflow));
Errors
pub fn checked_div_integer(&self, divisor: T) -> Result<Self, ConversionError>
[src]
Checked Period
/ integer = Period
Examples
assert_eq!(<Period>::new(1000, 1).checked_div_integer(5_u32), Ok(<Period>::new(200, 1))); assert_eq!(<Period>::new(1, 1000).checked_div_integer(5_u32), Ok(<Period>::new(1, 5000))); assert_eq!(<Period>::new(1, u32::MAX).checked_div_integer(2_u32), Err(ConversionError::Overflow));
Errors
Trait Implementations
impl<T: Debug> Debug for Period<T>
[src]
impl<T> Div<Period<T>> for Period<T> where
T: TimeInt,
[src]
T: TimeInt,
type Output = Self
The resulting type after applying the /
operator.
fn div(self, rhs: Self) -> Self::Output
[src]
assert_eq!(Period::<u32>::new(1000, 1) / <Period>::new(10, 1_000), <Period>::new(1_000_000, 10));
impl<T> Mul<Period<T>> for Period<T> where
T: TimeInt,
[src]
T: TimeInt,
type Output = Self
The resulting type after applying the *
operator.
fn mul(self, rhs: Self) -> Self::Output
[src]
assert_eq!(Period::<u32>::new(1000, 1) * <Period>::new(5,5), <Period>::new(5_000, 5));
impl<T: TimeInt> PartialEq<Period<T>> for Period<T>
[src]
impl<T: TimeInt> PartialOrd<Period<T>> for Period<T>
[src]
fn partial_cmp(&self, other: &Self) -> Option<Ordering>
[src]
#[must_use]fn lt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn le(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn gt(&self, other: &Rhs) -> bool
1.0.0[src]
#[must_use]fn ge(&self, other: &Rhs) -> bool
1.0.0[src]
impl<T: TimeInt> TryFrom<Hertz<T>> for Period<T>
[src]
type Error = ConversionError
The type returned in the event of a conversion error.
fn try_from(freq: Hertz<T>) -> Result<Self, Self::Error>
[src]
impl<T: TimeInt> TryFrom<Period<T>> for Hertz<T>
[src]
type Error = ConversionError
The type returned in the event of a conversion error.
fn try_from(period: Period<T>) -> Result<Self, Self::Error>
[src]
Create a new Frequency
from a fractional Period
in seconds
Examples
assert_eq!(Hertz::try_from(<Period>::new(1, 1_000)), Ok(Hertz(1_000_u32))); assert_eq!(Hertz::try_from(<Period>::new(0, 1_000)), Err(ConversionError::DivByZero)); assert_eq!(<Period>::new(1, 1_000).try_into(), Ok(Hertz(1_000_u32)));
Errors
Auto Trait Implementations
impl<T> RefUnwindSafe for Period<T> where
T: RefUnwindSafe,
T: RefUnwindSafe,
impl<T> Send for Period<T> where
T: Send,
T: Send,
impl<T> Sync for Period<T> where
T: Sync,
T: Sync,
impl<T> Unpin for Period<T> where
T: Unpin,
T: Unpin,
impl<T> UnwindSafe for Period<T> where
T: UnwindSafe,
T: UnwindSafe,
Blanket Implementations
impl<T> Any for T where
T: 'static + ?Sized,
[src]
T: 'static + ?Sized,
impl<T> Borrow<T> for T where
T: ?Sized,
[src]
T: ?Sized,
impl<T> BorrowMut<T> for T where
T: ?Sized,
[src]
T: ?Sized,
fn borrow_mut(&mut self) -> &mut T
[src]
impl<T> From<T> for T
[src]
impl<T, U> Into<U> for T where
U: From<T>,
[src]
U: From<T>,
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.
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>,