Skip to main content

Storage

Trait Storage 

Source
pub trait Storage {
    // Required methods
    fn read(
        &mut self,
        block: u32,
        offset: u32,
        buf: &mut [u8],
    ) -> Result<(), Error>;
    fn write(
        &mut self,
        block: u32,
        offset: u32,
        data: &[u8],
    ) -> Result<(), Error>;
    fn erase(&mut self, block: u32) -> Result<(), Error>;

    // Provided method
    fn sync(&mut self) -> Result<(), Error> { ... }
}
Expand description

Block device storage backend.

Implement this trait to connect a flash chip, SD card, or any other block device. See RamStorage for a minimal example.

Required Methods§

Source

fn read(&mut self, block: u32, offset: u32, buf: &mut [u8]) -> Result<(), Error>

Read buf.len() bytes starting at offset within block.

Source

fn write(&mut self, block: u32, offset: u32, data: &[u8]) -> Result<(), Error>

Write data starting at offset within block.

The block must have been erased before writing.

Source

fn erase(&mut self, block: u32) -> Result<(), Error>

Erase block, resetting all bytes to the erased state (typically 0xFF).

Provided Methods§

Source

fn sync(&mut self) -> Result<(), Error>

Flush pending writes. The default implementation is a no-op.

Implementors§