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 7, 2018
1 parent 98a6fb8 commit 0a38a9c
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@
.#*
/target/
Cargo.lock
.*.sw*
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 0a38a9c

Please sign in to comment.