Skip to main content

Flash

Struct Flash 

Source
pub struct Flash { /* private fields */ }
Expand description

Simulated NOR Flash storage

Implementations§

Source§

impl Flash

Source

pub fn new() -> Self

Create new flash simulation with default config (64KB)

Source

pub fn with_config(config: FlashConfig) -> Self

Create with custom configuration

Source

pub fn capacity(&self) -> usize

Get total capacity

Source

pub fn page_size(&self) -> usize

Get page size

Source

pub fn erase_page(&mut self, page: PageId) -> Result<()>

Erase a page (sets all bytes to 0xFF)

§Errors

Returns error if page index is out of range or max erase cycles exceeded

Source

pub fn write(&mut self, offset: usize, data: &[u8]) -> Result<()>

Write data to flash

Flash can only change bits from 1 to 0, not 0 to 1. Attempting to set a bit from 0 to 1 returns an error.

Source

pub fn read(&self, offset: usize, len: usize) -> Result<&[u8]>

Read data from flash

Source

pub fn get_erase_count(&self, page: PageId) -> Option<u32>

Get erase count for a page

Source

pub fn is_erased(&self, page: PageId) -> bool

Check if page is in erased state

Source

pub fn find_wear_leveled_pages(&self, count: usize) -> Vec<PageId>

Find pages with lowest erase counts (for wear leveling)

Source

pub fn total_erase_cycles(&self) -> u64

Get total erase cycles across all pages

Source

pub fn dump(&self, start: usize, len: usize) -> String

Dump flash contents as hex (for debugging)

Trait Implementations§

Source§

impl Debug for Flash

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Default for Flash

Source§

fn default() -> Self

Returns the “default value” for a type. Read more

Auto Trait Implementations§

§

impl Freeze for Flash

§

impl RefUnwindSafe for Flash

§

impl Send for Flash

§

impl Sync for Flash

§

impl Unpin for Flash

§

impl UnsafeUnpin for Flash

§

impl UnwindSafe for Flash

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
Source§

impl<V, T> VZip<V> for T
where V: MultiLane<T>,

Source§

fn vzip(self) -> V