Skip to content

Commit

Permalink
Add example of opaque CountDown type usage
Browse files Browse the repository at this point in the history
  • Loading branch information
Brandon Matthews committed Nov 8, 2018
1 parent 98a6fb8 commit 9a84bdb
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/timer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,23 @@ use void::Void;
/// # fn wait(&mut self) -> ::nb::Result<(), Void> { Ok(()) }
/// # }
/// ```
///
/// If you want to use a CountDown timer as an opaque type in a HAL-based driver, you have to add
/// some type bounds to make sure arguments passed to `start` can be used by the underlying
/// (concrete) `CountDown::Time` type:
/// ```rust
/// extern crate embedded_hal as hal;
/// #[macro_use(block)]
///
/// pub fn uses_timer<T, U>(t: T)
/// where
/// T: hal::timer::CountDown<Time=U>,
/// U: From<u32>,
/// {
/// // delay an arbitrary 1 time unit
/// t.start(1);
/// }
/// ```
pub trait CountDown {
/// The unit of time used by this timer
type Time;
Expand Down

0 comments on commit 9a84bdb

Please sign in to comment.