From 0a38a9c25f24c480f1564fb9e3264ec0dd79faff Mon Sep 17 00:00:00 2001 From: Brandon Matthews Date: Wed, 7 Nov 2018 09:26:53 -0800 Subject: [PATCH] Add example of opaque CountDown type usage --- .gitignore | 1 + src/timer.rs | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/.gitignore b/.gitignore index f8d7c8b49..2949c0d1d 100644 --- a/.gitignore +++ b/.gitignore @@ -2,3 +2,4 @@ .#* /target/ Cargo.lock +.*.sw* diff --git a/src/timer.rs b/src/timer.rs index 74cf088f3..b14ca5ba2 100644 --- a/src/timer.rs +++ b/src/timer.rs @@ -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: T) +/// where +/// T: hal::timer::CountDown, +/// U: From, +/// { +/// // delay an arbitrary 1 time unit +/// t.start(1); +/// } +/// ``` pub trait CountDown { /// The unit of time used by this timer type Time;