sfkv/src/no_flash.rs
2020-12-11 18:07:39 +01:00

34 lines
769 B
Rust

use crate::StoreBackend;
use core::fmt;
/// expect this for any write operation to `NoFlash`
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub struct NoFlashError;
impl fmt::Display for NoFlashError {
fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
write!(f, "no flash")
}
}
/// a valid `StoreBackend` that can be used for configurations lacking a flash
#[derive(Debug, Clone, Copy)]
pub struct NoFlash;
impl StoreBackend for NoFlash {
type Data = [u8; 0];
fn data(&self) -> &Self::Data {
&[]
}
type Error = NoFlashError;
fn erase(&mut self) -> Result<(), Self::Error> {
Err(NoFlashError)
}
fn program(&mut self, _: usize, _: &[u8]) -> Result<(), Self::Error> {
Err(NoFlashError)
}
}