ekv

Crates

git

Versions

default

Flavors

ekv::flash

Trait Flash

Source
pub trait Flash {
    type Error: Debug;

    // Required methods
    fn page_count(&self) -> usize;
    async fn erase(&mut self, page_id: PageID) -> Result<(), Self::Error>;
    async fn read(
        &mut self,
        page_id: PageID,
        offset: usize,
        data: &mut [u8],
    ) -> Result<(), Self::Error>;
    async fn write(
        &mut self,
        page_id: PageID,
        offset: usize,
        data: &[u8],
    ) -> Result<(), Self::Error>;
}
Expand description

Flash storage trait

Required Associated Types§

Source

type Error: Debug

Error type for the flash operations.

Required Methods§

Source

fn page_count(&self) -> usize

Get the page count of the flash storage.

Source

async fn erase(&mut self, page_id: PageID) -> Result<(), Self::Error>

Erase a page.

If power is lost during an erase, the resulting data is allowed to be anything, but data on other pages must stay unaffected.

After erasing, all bytes in the page must be equal to ERASE_VALUE.

Source

async fn read( &mut self, page_id: PageID, offset: usize, data: &mut [u8], ) -> Result<(), Self::Error>

Read data.

offset and data.len() are guaranteed to be a multiple of ALIGN.

Source

async fn write( &mut self, page_id: PageID, offset: usize, data: &[u8], ) -> Result<(), Self::Error>

Write data.

If power is lost during a write, the resulting data in the written bytes is allowed to be anything, but data on other bytes within the page must stay unaffected. This means it is NOT okay to implement this with underlying “read-erase-modify-write” strategies.

offset and data.len() are guaranteed to be a multiple of ALIGN.

It is guaranteed that each byte will be written only once after each erase. This ensures maximum compatibility with different flash hardware, in particular flash memory with ECC.

Dyn Compatibility§

This trait is not dyn compatible.

In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.

Implementations on Foreign Types§

Source§

impl<T: Flash> Flash for &mut T

Source§

type Error = <T as Flash>::Error

Source§

fn page_count(&self) -> usize

Source§

async fn erase(&mut self, page_id: PageID) -> Result<(), Self::Error>

Source§

async fn read( &mut self, page_id: PageID, offset: usize, data: &mut [u8], ) -> Result<(), Self::Error>

Source§

async fn write( &mut self, page_id: PageID, offset: usize, data: &[u8], ) -> Result<(), Self::Error>

Implementors§