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§
Required Methods§
Sourcefn page_count(&self) -> usize
fn page_count(&self) -> usize
Get the page count of the flash storage.
Sourceasync fn erase(&mut self, page_id: PageID) -> Result<(), Self::Error>
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
.
Sourceasync fn read(
&mut self,
page_id: PageID,
offset: usize,
data: &mut [u8],
) -> Result<(), Self::Error>
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
.
Sourceasync fn write(
&mut self,
page_id: PageID,
offset: usize,
data: &[u8],
) -> Result<(), Self::Error>
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.