# _embedded_hal_timer_CountDown in k210_hal::prelude - Rust
A count down timer
Keywords: rust, rustlang, rust-lang, _embedded_hal_timer_CountDown

# Trait k210_hal::prelude::_embedded_hal_timer_CountDown

source · [−]

    pub trait _embedded_hal_timer_CountDown {
        type Error;
        type Time;
        fn try_start<T>(&mut self, count: T) -> Result<(), Self::Error>
        where
            T: Into<Self::Time>;
        fn try_wait(&mut self) -> Result<(), Error<Self::Error>>;
    }

Expand description

A count down timer

## Contract

- `self.start(count); block!(self.try_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

    extern crate embedded_hal as hal;
    #[macro_use(block)]
    extern crate nb;

    use hal::prelude::*;

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

        Led.on();
        timer.try_start(1.s()).unwrap();
        block!(timer.try_wait()); // blocks for 1 second
        Led.off();
    }

## Associated Types

source

#### type Error

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 try_start<T>(&mut self, count: T) -> Result<(), Self::Error> where
T: Into<Self::Time>,

Starts a new count down

source

#### fn try_wait(&mut self) -> Result<(), Error<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 `try_wait` after the last call returned `Ok` is UNSPECIFIED. Implementers are suggested to panic on this scenario to signal a programmer error.

## Implementors