Trait CountDown

Source
pub trait CountDown {
    type Error: Debug;
    type Time;

    // Required methods
    fn start<T>(&mut self, count: T) -> Result<(), Self::Error>
       where T: Into<Self::Time>;
    fn wait(&mut self) -> Result<(), Self::Error>;
}
Expand description

A count down timer

Note that this is borrowed from embedded-hal 0.2.x and will be in use until the 1.x version provides one.

§Contract

  • self.start(count); block!(self.wait()); MUST block for AT LEAST the time specified by count.

Note that the implementer doesn’t necessarily have to be a downcounting timer; it could also be an upcounting timer as long as the above contract is upheld.

§Examples

You can use this timer to create delays

use std::time::Duration;
use nb::block;
use linux_embedded_hal::{CountDown, SysTimer};

fn main() {
    let mut led: Led = {
        // ..
    };
    let mut timer = SysTimer::new();

    Led.on();
    timer.start(Duration::from_millis(1000)).unwrap();
    block!(timer.wait()); // blocks for 1 second
    Led.off();
}

Required Associated Types§

Source

type Error: Debug

An enumeration of CountDown errors.

For infallible implementations, will be Infallible

Source

type Time

The unit of time used by this timer

Required Methods§

Source

fn start<T>(&mut self, count: T) -> Result<(), Self::Error>
where T: Into<Self::Time>,

Starts a new count down

Source

fn wait(&mut self) -> Result<(), Self::Error>

Non-blockingly “waits” until the count down finishes

§Contract
  • If Self: Periodic, the timer will start a new count down right after the last one finishes.
  • Otherwise the behavior of calling wait after the last call returned Ok is UNSPECIFIED. Implementers are suggested to panic on this scenario to signal a programmer error.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<T: CountDown> CountDown for &mut T

Source§

type Error = <T as CountDown>::Error

Source§

type Time = <T as CountDown>::Time

Source§

fn start<TIME>(&mut self, count: TIME) -> Result<(), Self::Error>
where TIME: Into<Self::Time>,

Source§

fn wait(&mut self) -> Result<(), Self::Error>

Implementors§