embedded_storage/lib.rs
1//! # embedded-storage - A Storage Abstraction Layer for Embedded Systems
2//!
3//! Storage traits to allow on and off board storage devices to read and write
4//! data.
5
6#![doc(html_root_url = "https://docs.rs/embedded-storage/0.1.0")]
7#![no_std]
8#![deny(missing_docs)]
9#![deny(unsafe_code)]
10
11/// Currently contains [`OverlapIterator`]
12pub mod iter;
13/// Technology specific traits for NOR Flashes
14pub mod nor_flash;
15
16/// A region denotes a contiguous piece of memory between two addresses.
17pub trait Region {
18 /// Check if `address` is contained in the region of `Self`
19 fn contains(&self, address: u32) -> bool;
20}
21
22/// Transparent read only storage trait
23pub trait ReadStorage {
24 /// An enumeration of storage errors
25 type Error;
26
27 /// Read a slice of data from the storage peripheral, starting the read
28 /// operation at the given address offset, and reading `bytes.len()` bytes.
29 ///
30 /// This should throw an error in case `bytes.len()` will be larger than
31 /// `self.capacity() - offset`.
32 fn read(&mut self, offset: u32, bytes: &mut [u8]) -> Result<(), Self::Error>;
33
34 /// The capacity of the storage peripheral in bytes.
35 fn capacity(&self) -> usize;
36}
37
38/// Transparent read/write storage trait
39pub trait Storage: ReadStorage {
40 /// Write a slice of data to the storage peripheral, starting the write
41 /// operation at the given address offset (between 0 and `self.capacity()`).
42 ///
43 /// **NOTE:**
44 /// This function will automatically erase any pages necessary to write the given data,
45 /// and might as such do RMW operations at an undesirable performance impact.
46 fn write(&mut self, offset: u32, bytes: &[u8]) -> Result<(), Self::Error>;
47}