Skip to content

Commit 0a38a9c

Browse files
author
Brandon Matthews
committed
Add example of opaque CountDown type usage
1 parent 98a6fb8 commit 0a38a9c

File tree

2 files changed

+18
-0
lines changed

2 files changed

+18
-0
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,3 +2,4 @@
22
.#*
33
/target/
44
Cargo.lock
5+
.*.sw*

src/timer.rs

+17
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,23 @@ use void::Void;
5757
/// # fn wait(&mut self) -> ::nb::Result<(), Void> { Ok(()) }
5858
/// # }
5959
/// ```
60+
///
61+
/// If you want to use a CountDown timer as an opaque type in a HAL-based driver, you have to add
62+
/// some type bounds to make sure arguments passed to `start` can be used by the underlying
63+
/// (concrete) `CountDown::Time` type:
64+
/// ```rust
65+
/// extern crate embedded_hal as hal;
66+
/// #[macro_use(block)]
67+
///
68+
/// pub fn uses_timer<T, U>(t: T)
69+
/// where
70+
/// T: hal::timer::CountDown<Time=U>,
71+
/// U: From<u32>,
72+
/// {
73+
/// // delay an arbitrary 1 time unit
74+
/// t.start(1);
75+
/// }
76+
/// ```
6077
pub trait CountDown {
6178
/// The unit of time used by this timer
6279
type Time;

0 commit comments

Comments
 (0)