From 9a84bdbef78bbbd22d13df1aa9300c67a998ab02 Mon Sep 17 00:00:00 2001 From: Brandon Matthews Date: Wed, 7 Nov 2018 09:26:53 -0800 Subject: [PATCH 1/3] Add example of opaque CountDown type usage --- src/timer.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) 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; From d3497f88fa107df528a19769b1e21aa2b44346cd Mon Sep 17 00:00:00 2001 From: Daniel Egger Date: Thu, 8 Nov 2018 07:39:52 -0800 Subject: [PATCH 2/3] Remove unused block macro incl Co-Authored-By: thenewwazoo --- src/timer.rs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/timer.rs b/src/timer.rs index b14ca5ba2..7bf0f2f8c 100644 --- a/src/timer.rs +++ b/src/timer.rs @@ -63,7 +63,6 @@ use void::Void; /// (concrete) `CountDown::Time` type: /// ```rust /// extern crate embedded_hal as hal; -/// #[macro_use(block)] /// /// pub fn uses_timer(t: T) /// where From 6e2e5c18bbb96fd8928b40a5087ea2718a2841bd Mon Sep 17 00:00:00 2001 From: Brandon Matthews Date: Fri, 9 Nov 2018 14:25:19 -0800 Subject: [PATCH 3/3] fix doc example --- src/timer.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/timer.rs b/src/timer.rs index 7bf0f2f8c..84d5720a1 100644 --- a/src/timer.rs +++ b/src/timer.rs @@ -64,7 +64,7 @@ use void::Void; /// ```rust /// extern crate embedded_hal as hal; /// -/// pub fn uses_timer(t: T) +/// pub fn uses_timer(t: &mut T) /// where /// T: hal::timer::CountDown, /// U: From,