embedded_storage_async/lib.rs
1//! # embedded-storage-async - An async Storage Abstraction Layer for Embedded Systems
2//!
3//! Storage traits to allow on and off board storage devices to read and write
4//! data asynchronously.
5
6#![no_std]
7#![allow(async_fn_in_trait)]
8
9pub mod nor_flash;
10
11/// Transparent read only storage trait
12pub trait ReadStorage {
13 /// An enumeration of storage errors
14 type Error;
15
16 /// Read a slice of data from the storage peripheral, starting the read
17 /// operation at the given address offset, and reading `bytes.len()` bytes.
18 ///
19 /// This should throw an error in case `bytes.len()` will be larger than
20 /// `self.capacity() - offset`.
21 async fn read(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Self::Error>;
22
23 /// The capacity of the storage peripheral in bytes.
24 fn capacity(&self) -> usize;
25}
26
27/// Transparent read/write storage trait
28pub trait Storage: ReadStorage {
29 /// Write a slice of data to the storage peripheral, starting the write
30 /// operation at the given address offset (between 0 and `self.capacity()`).
31 ///
32 /// **NOTE:**
33 /// This function will automatically erase any pages necessary to write the given data,
34 /// and might as such do RMW operations at an undesirable performance impact.
35 async fn write(&mut self, offset: u32, bytes: &[u8]) -> Result<(), Self::Error>;
36}