Skip to content

Commit 4d02ea1

Browse files
committed
Add futures::Delay trait
1 parent b79bf16 commit 4d02ea1

File tree

5 files changed

+31
-125
lines changed

5 files changed

+31
-125
lines changed

src/futures/delay.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
//! Asynchronous Delays
2+
//!
3+
//! # What's the difference this trait and the `timer::CountDown` trait?
4+
//!
5+
//! The `Delay` trait provides an asynchronous delay abstraction and it's meant to be used either
6+
//! to build higher-level abstractions like I/O timeouts or by itself.
7+
8+
use core::future::Future;
9+
10+
/// Asynchronously wait a duration of time.
11+
pub trait Delay {
12+
/// Enumeration of `Delay` errors.
13+
type Error;
14+
15+
/// The future returned from `delay`.
16+
type DelayFuture<'a>: Future<Output = Result<(), Self::Error>> + 'a
17+
where
18+
Self: 'a;
19+
20+
/// The unit of time used by this delay timer.
21+
type Time;
22+
23+
/// Returns a future that will resolve when `duration` has passed.
24+
/// It is not guaranteed that _exactly_ `duration` will pass, but it will
25+
/// be `duration` or longer.
26+
fn delay<'a>(&mut self, duration: impl Into<Self::Time>) -> Self::DelayFuture<'a>;
27+
}

src/futures/mod.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
//! This traits use `core::future::Future` and generic associated types.
44
55
pub mod i2c;
6-
pub mod rng;
76
pub mod serial;
87
pub mod spi;
9-
pub mod timer;
8+
pub mod delay;

src/futures/rng.rs

Lines changed: 0 additions & 19 deletions
This file was deleted.

src/futures/spi.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ pub trait TransferInPlace<W: 'static> {
3131
/// This method uses a single `readwrite` buffer.
3232
///
3333
/// The returned buffer is the initialized `readwrite` buffer.
34-
fn transfer_inplace<'a>(&'a mut self, readwrite: &'a mut [W]) -> Self::TransferInPlaceFuture<'a>;
34+
fn transfer_inplace<'a>(&'a mut self, words: &'a mut [W]) -> Self::TransferInPlaceFuture<'a>;
3535
}
3636

3737
/// Async write
@@ -45,7 +45,7 @@ pub trait Write<W> {
4545
Self: 'a;
4646

4747
/// Writes `words` to the slave, ignoring all the incoming words
48-
fn write<'a>(&'a mut self, words: &'a [W]) -> Self::WriteFuture<'a>;
48+
fn write<'a>(&'a mut self, write: &'a [W]) -> Self::WriteFuture<'a>;
4949
}
5050

5151
/// Async read
@@ -63,5 +63,5 @@ pub trait Read<W: 'static> {
6363
/// by this trait. Some hardware can configure what values (e.g. 0x00, 0xFF), some cannot.
6464
///
6565
/// The returned buffer is the initialized `words` buffer.
66-
fn read<'a>(&'a mut self, words: &'a mut [W]) -> Self::ReadFuture<'a>;
66+
fn read<'a>(&'a mut self, read: &'a mut [W]) -> Self::ReadFuture<'a>;
6767
}

src/futures/timer.rs

Lines changed: 0 additions & 101 deletions
This file was deleted.

0 commit comments

Comments
 (0)