BufferStorage

Struct BufferStorage 

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

Simulates a flash storage using a buffer in memory.

This buffer storage can be used in place of an actual flash storage. It is particularly useful for tests and fuzzing, for which it has dedicated functionalities.

This storage tracks how many times words are written between page erase cycles, how many times pages are erased, and whether an operation flips bits in the wrong direction. Operations panic if those conditions are broken (optional). This storage also permits to interrupt operations for inspection or to corrupt the operation.

Implementations§

Source§

impl BufferStorage

Source

pub fn new(storage: Box<[u8]>, options: BufferOptions) -> BufferStorage

Creates a buffer storage.

§Panics

The following preconditions must hold:

  • options.word_size must be a power of two.
  • options.page_size must be a power of two.
  • options.page_size must be word-aligned.
  • storage.len() must be page-aligned.
Source

pub fn arm_interruption(&mut self, delay: usize)

Arms an interruption after a given delay.

Before each subsequent mutable operation (write or erase), the delay is decremented if positive. If the delay is elapsed, the operation is saved and the INTERRUPTION error is returned. Subsequent operations will panic until either of:

§Panics

Panics if an interruption is already armed.

Source

pub fn disarm_interruption(&mut self) -> usize

Disarms an interruption that did not trigger.

Returns the remaining delay.

§Panics

Panics if any of the following conditions hold:

  • An interruption was not armed.
  • An interruption was armed and it has triggered.
Source

pub fn reset_interruption(&mut self)

Resets an interruption regardless of triggering.

§Panics

Panics if an interruption was not armed.

Source

pub fn corrupt_operation(&mut self, corrupt: BufferCorruptFunction<'_>)

Corrupts an interrupted operation.

Applies the corruption function to the storage. Counters are updated accordingly:

  • If a word is fully written, its counter is incremented regardless of whether other words of the same operation have been fully written.
  • If a page is fully erased, its counter is incremented (and its word counters are reset).
§Panics

Panics if any of the following conditions hold:

  • An interruption was not armed.
  • An interruption was armed but did not trigger.
  • The corruption function corrupts more bits than allowed.
  • The interrupted operation itself would have panicked.
Source

pub fn get_word_writes(&self, word: usize) -> usize

Returns the number of times a word was written.

Source

pub fn get_page_erases(&self, page: usize) -> usize

Returns the number of times a page was erased.

Source

pub fn set_page_erases(&mut self, page: usize, cycle: usize)

Sets the number of times a page was erased.

Trait Implementations§

Source§

impl Clone for BufferStorage

Source§

fn clone(&self) -> BufferStorage

Returns a duplicate of the value. Read more
1.0.0 · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Display for BufferStorage

Source§

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

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

impl Storage for BufferStorage

Source§

fn word_size(&self) -> usize

The size of a word in bytes. Read more
Source§

fn page_size(&self) -> usize

The size of a page in bytes. Read more
Source§

fn num_pages(&self) -> usize

The number of pages in the storage.
Source§

fn max_word_writes(&self) -> usize

Maximum number of times a word can be written between page erasures.
Source§

fn max_page_erases(&self) -> usize

Maximum number of times a page can be erased.
Source§

fn read_slice( &self, index: StorageIndex, length: usize, ) -> Result<Cow<'_, [u8]>, Error>

Reads a byte slice from the storage. Read more
Source§

fn write_slice( &mut self, index: StorageIndex, value: &[u8], ) -> Result<(), Error>

Writes a word slice to the storage. Read more
Source§

fn erase_page(&mut self, page: usize) -> Result<(), Error>

Erases a page of the storage. Read more

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
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.