[][src]Trait embedded_time::TimeInt

pub trait TimeInt: Copy + Integer + Bounded + WrappingAdd + WrappingSub + CheckedMul + CheckedDiv + From<i32> + TryInto<i32> + TryFrom<i64> + TryInto<u64> + Into<i64> + TryFrom<u128> + Display + Debug {
    fn nanoseconds(self) -> Nanoseconds<Self>;
fn microseconds(self) -> Microseconds<Self>;
fn milliseconds(self) -> Milliseconds<Self>;
fn seconds(self) -> Seconds<Self>;
fn minutes(self) -> Minutes<Self>;
fn hours(self) -> Hours<Self>;
fn hertz(self) -> Hertz<Self>; fn checked_mul_period(&self, period: &Period) -> Option<Self> { ... }
fn checked_div_period(&self, period: &Period) -> Option<Self> { ... } }

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

Loading content...

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));
Loading content...

Implementors

impl TimeInt for i32[src]

impl TimeInt for i64[src]

Loading content...