[−][src]Trait embedded_time::TimeInt
Create time-based values from primitive and core numeric types.
This trait can be imported with use embedded-time::prelude::*
.
Examples
Basic construction of time-based values.
assert_eq!(5.nanoseconds(), Nanoseconds(5)); assert_eq!(5.microseconds(), Microseconds(5)); assert_eq!(5.milliseconds(), Milliseconds(5)); assert_eq!(5.seconds(), Seconds(5)); assert_eq!(5.minutes(), Minutes(5)); assert_eq!(5.hours(), Hours(5)); assert_eq!(5.hertz(), Hertz(5));
Signed integers work as well!
assert_eq!((-5).nanoseconds(), Nanoseconds(-5)); assert_eq!((-5).microseconds(), Microseconds(-5)); assert_eq!((-5).milliseconds(), Milliseconds(-5)); assert_eq!((-5).seconds(), Seconds(-5)); assert_eq!((-5).minutes(), Minutes(-5)); assert_eq!((-5).hours(), Hours(-5));
Required methods
fn nanoseconds(self) -> Nanoseconds<Self>
Construct the Duration
implementation
fn microseconds(self) -> Microseconds<Self>
Construct the Duration
implementation
fn milliseconds(self) -> Milliseconds<Self>
Construct the Duration
implementation
fn seconds(self) -> Seconds<Self>
Construct the Duration
implementation
fn minutes(self) -> Minutes<Self>
Construct the Duration
implementation
fn hours(self) -> Hours<Self>
Construct the Duration
implementation
fn hertz(self) -> Hertz<Self>
Construct the frequency type
Provided methods
fn checked_mul_period(&self, period: &Period) -> Option<Self>
assert_eq!(8_i32.checked_mul_period(&Period::new(1,2)), Some(4_i32)); // the result is not rounded, but truncated assert_eq!(8_i32.checked_mul_period(&Period::new(1,3)), Some(2_i32));
fn checked_div_period(&self, period: &Period) -> Option<Self>
assert_eq!(8_i32.checked_div_period(&Period::new(1,2)), Some(16_i32)); assert_eq!(8_i32.checked_div_period(&Period::new(3,2)), Some(5_i32));