pub struct RemovableFlash<F> { /* private fields */ }std only.Expand description
Test double for removable media: any flash that can be made absent.
Wraps an inner flash and gates every operation on a presence flag. While absent, reads fail too, not just writes — a card yanked between writing a spool intent record and reading the next payload must exercise both paths.
The inner flash is retained while absent, so insert restores
exactly the bytes that were there before, and into_inner
models carrying the card to a computer.
§Example
use sensor_db::mock::{MockFlash, RemovableFlash};
let mut card = RemovableFlash::new(MockFlash::<256, 4096>::new(8 * 4096));
assert!(card.is_present());
card.remove();
assert!(!card.is_present());
card.insert();Implementations§
Source§impl<F> RemovableFlash<F>
impl<F> RemovableFlash<F>
Sourcepub fn remove(&mut self)
pub fn remove(&mut self)
Remove the medium cleanly. Subsequent reads and writes fail with
MockFlashError::NotPresent.
Sourcepub fn yank_after(&mut self, n: u64)
pub fn yank_after(&mut self, n: u64)
Become absent after n further writes — a surprise yank mid-batch.
The n-th write from now still succeeds; the one after it fails. Use
this to land a removal in the middle of a multi-page operation.
Sourcepub fn is_present(&self) -> bool
pub fn is_present(&self) -> bool
Whether the medium is currently present.
Sourcepub fn write_count(&self) -> u64
pub fn write_count(&self) -> u64
Total writes attempted while present.
Sourcepub fn into_inner(self) -> F
pub fn into_inner(self) -> F
Consume the wrapper and return the flash — “carry the card to the laptop”.
Trait Implementations§
Source§impl<F: Clone> Clone for RemovableFlash<F>
impl<F: Clone> Clone for RemovableFlash<F>
Source§impl<F> ErrorType for RemovableFlash<F>
impl<F> ErrorType for RemovableFlash<F>
Source§type Error = MockFlashError
type Error = MockFlashError
Source§impl<F> NorFlash for RemovableFlash<F>where
F: NorFlash<Error = MockFlashError>,
impl<F> NorFlash for RemovableFlash<F>where
F: NorFlash<Error = MockFlashError>,
Source§const WRITE_SIZE: usize = F::WRITE_SIZE
const WRITE_SIZE: usize = F::WRITE_SIZE
Source§const ERASE_SIZE: usize = F::ERASE_SIZE
const ERASE_SIZE: usize = F::ERASE_SIZE
Source§impl<F> ReadNorFlash for RemovableFlash<F>where
F: ReadNorFlash<Error = MockFlashError>,
impl<F> ReadNorFlash for RemovableFlash<F>where
F: ReadNorFlash<Error = MockFlashError>,
Source§impl<F> Removable for RemovableFlash<F>
impl<F> Removable for RemovableFlash<F>
Source§fn is_present(&self) -> bool
fn is_present(&self) -> bool
true while the medium is believed present and usable.