Skip to content

Commit eb2ff8a

Browse files
committed
Fix some docs in the futures module
1 parent 85accbd commit eb2ff8a

File tree

2 files changed

+25
-6
lines changed

2 files changed

+25
-6
lines changed

src/futures/delay.rs

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,18 @@
88
use core::{future::Future, time::Duration};
99

1010
/// Asynchronously wait a duration of time.
11+
///
12+
/// # Example
13+
/// ```rust
14+
/// # use embedded_hal::futures::delay::Delay;
15+
/// use core::time::Duration;
16+
///
17+
/// async fn wait_100_micros<D: Delay>(timer: &D) {
18+
/// timer.delay(Duration::from_micros(100))
19+
/// .await
20+
/// .expect("failed to await on timer");
21+
/// }
22+
/// ```
1123
pub trait Delay {
1224
/// Enumeration of `Delay` errors.
1325
type Error;

src/futures/digital.rs

Lines changed: 13 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,18 @@ use crate::blocking::digital::InputPin;
1414
/// where
1515
/// P: AsyncInputPin,
1616
/// {
17-
/// ready_pin.until_high().await
17+
/// ready_pin
18+
/// .until_high()
19+
/// .await
20+
/// .expect("failed to await input pin")
1821
/// }
1922
/// ```
2023
///
2124
/// ```rust,ignore
2225
/// # use embedded_hal::futures::digital::AsyncInputPin;
2326
/// # use embedded_hal::futures::delay::Delay;
24-
/// # use core::time::Duration;
27+
/// use core::time::Duration;
28+
///
2529
/// /// Wait until the `ready_pin` is high or timeout after 1 millisecond.
2630
/// /// Returns true is the pin became high or false if it timed-out.
2731
/// async fn wait_until_ready_or_timeout<P, D>(ready_pin: &P, delay: &mut D) -> bool
@@ -30,17 +34,20 @@ use crate::blocking::digital::InputPin;
3034
/// D: Delay,
3135
/// {
3236
/// futures::select_biased! {
33-
/// _ => ready_pin.until_high() => true,
34-
/// _ => delay.delay(Duration::from_millis(1)) => false,
37+
/// x => ready_pin.until_high() => {
38+
/// x.expect("failed to await input pin");
39+
/// true
40+
/// },
41+
/// _ => delay.delay(Duration::from_millis(1)) => false, // ignore the error
3542
/// }
3643
/// }
3744
/// ```
3845
pub trait AsyncInputPin: InputPin {
3946
/// The future returned by the `until_high` function.
40-
type UntilHighFuture<'a>: Future<Output=()> + 'a;
47+
type UntilHighFuture<'a>: Future<Output=Result<(), Self::Error>> + 'a;
4148

4249
/// The future returned by the `until_low` function.
43-
type UntilLowFuture<'a>: Future<Output=()> + 'a;
50+
type UntilLowFuture<'a>: Future<Output=Result<(), Self::Error>> + 'a;
4451

4552
/// Returns a future that resolves when this pin becomes high.
4653
fn until_high<'a>(&self) -> Self::UntilHighFuture<'a>;

0 commit comments

Comments
 (0)