sfkv/src/no_flash.rs

38 lines
842 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)
}
fn backup_space(&self) -> &'static mut [u8] {
&mut []
}
}