Skip to main content

littlefs_rust/
storage.rs

1use crate::error::Error;
2
3/// Block device storage backend.
4///
5/// Implement this trait to connect a flash chip, SD card, or any other block
6/// device. See [`RamStorage`](crate::RamStorage) for a minimal example.
7pub trait Storage {
8    /// Read `buf.len()` bytes starting at `offset` within `block`.
9    fn read(&mut self, block: u32, offset: u32, buf: &mut [u8]) -> Result<(), Error>;
10
11    /// Write `data` starting at `offset` within `block`.
12    ///
13    /// The block must have been erased before writing.
14    fn write(&mut self, block: u32, offset: u32, data: &[u8]) -> Result<(), Error>;
15
16    /// Erase `block`, resetting all bytes to the erased state (typically `0xFF`).
17    fn erase(&mut self, block: u32) -> Result<(), Error>;
18
19    /// Flush pending writes. The default implementation is a no-op.
20    fn sync(&mut self) -> Result<(), Error> {
21        Ok(())
22    }
23}