Skip to content

Commit a1d39f5

Browse files
Ulf Lilleengeneldruin
authored andcommitted
feat: use async futures in traits
1 parent ef20738 commit a1d39f5

File tree

4 files changed

+11
-17
lines changed

4 files changed

+11
-17
lines changed

embedded-storage-async/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "embedded-storage-async"
3-
version = "0.3.0"
3+
version = "0.4.0"
44
authors = [
55
"Mathias Koch <mk@blackbird.online>",
66
]
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
# Before upgrading check that everything is available on all tier1 targets here:
2+
# https://rust-lang.github.io/rustup-components-history
3+
[toolchain]
4+
channel = "nightly-2022-11-22"
5+
components = ["clippy"]

embedded-storage-async/src/lib.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
//! data asynchronously.
55
66
#![no_std]
7-
#![feature(generic_associated_types)]
7+
#![feature(async_fn_in_trait)]
8+
#![allow(incomplete_features)]
89

910
pub mod nor_flash;
Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,18 @@
1-
use core::future::Future;
21
use embedded_storage::nor_flash::ErrorType;
32

43
/// Read only NOR flash trait.
54
pub trait AsyncReadNorFlash: ErrorType {
65
/// The minumum number of bytes the storage peripheral can read
76
const READ_SIZE: usize;
87

9-
type ReadFuture<'a>: Future<Output = Result<(), Self::Error>> + 'a
10-
where
11-
Self: 'a;
12-
138
/// Read a slice of data from the storage peripheral, starting the read
149
/// operation at the given address offset, and reading `bytes.len()` bytes.
1510
///
1611
/// # Errors
1712
///
1813
/// Returns an error if the arguments are not aligned or out of bounds. The implementation
1914
/// can use the [`check_read`] helper function.
20-
fn read<'a>(&'a mut self, offset: u32, bytes: &'a mut [u8]) -> Self::ReadFuture<'a>;
15+
async fn read(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Self::Error>;
2116

2217
/// The capacity of the peripheral in bytes.
2318
fn capacity(&self) -> usize;
@@ -31,10 +26,6 @@ pub trait AsyncNorFlash: AsyncReadNorFlash {
3126
/// The minumum number of bytes the storage peripheral can erase
3227
const ERASE_SIZE: usize;
3328

34-
type EraseFuture<'a>: Future<Output = Result<(), Self::Error>> + 'a
35-
where
36-
Self: 'a;
37-
3829
/// Erase the given storage range, clearing all data within `[from..to]`.
3930
/// The given range will contain all 1s afterwards.
4031
///
@@ -45,11 +36,8 @@ pub trait AsyncNorFlash: AsyncReadNorFlash {
4536
/// Returns an error if the arguments are not aligned or out of bounds (the case where `to >
4637
/// from` is considered out of bounds). The implementation can use the [`check_erase`]
4738
/// helper function.
48-
fn erase<'a>(&'a mut self, from: u32, to: u32) -> Self::EraseFuture<'a>;
39+
async fn erase(&mut self, from: u32, to: u32) -> Result<(), Self::Error>;
4940

50-
type WriteFuture<'a>: Future<Output = Result<(), Self::Error>> + 'a
51-
where
52-
Self: 'a;
5341
/// If power is lost during write, the contents of the written words are undefined,
5442
/// but the rest of the page is guaranteed to be unchanged.
5543
/// It is not allowed to write to the same word twice.
@@ -58,5 +46,5 @@ pub trait AsyncNorFlash: AsyncReadNorFlash {
5846
///
5947
/// Returns an error if the arguments are not aligned or out of bounds. The implementation
6048
/// can use the [`check_write`] helper function.
61-
fn write<'a>(&'a mut self, offset: u32, bytes: &'a [u8]) -> Self::WriteFuture<'a>;
49+
async fn write(&mut self, offset: u32, bytes: &[u8]) -> Result<(), Self::Error>;
6250
}

0 commit comments

Comments
 (0)