pub struct FlashBlockEsp { /* private fields */ }Expand description
A device abstraction for type-safe persistent storage in flash memory.
FlashBlockEsp provides a generic flash-block storage system for ESP,
allowing you to store any serde-compatible type in the device’s internal flash.
Use FlashBlockEsp::new_array to allocate one or more blocks. Block operations like
load, save, and
clear are provided by FlashBlock, so bring the trait into
scope:
use device_envoy_esp::flash_block::FlashBlock as _;
§Features
- Type safety: Hash-based type checking prevents reading data written under a
different Rust type name. The hash is derived from the full type path
(for example,
app1::BootCounter). Trying to read a different type returnsOk(None). Structural changes (adding or removing fields) do not change the hash, but may cause deserialization to fail and return an error. - Postcard serialization: A compact,
no_std-friendly binary format.
§Block allocation
Conceptually, flash is treated as an array of fixed-size erase blocks counted from the end of the configured region backward. Your code can split that array using destructuring assignment and hand individual blocks to subsystems that need persistent storage.
⚠️ Warning: ESP firmware and user data share the same flash device. Allocating too many blocks can overwrite your firmware.
§Example
use device_envoy_esp::{Result, init_and_start, flash_block::{FlashBlockEsp, FlashBlock as _}};
#[derive(serde::Serialize, serde::Deserialize, Clone)]
struct WifiPersistedState {
ssid: heapless::String<32>,
password: heapless::String<64>,
timezone_offset_minutes: i32,
}
init_and_start!(p);
let [mut wifi_persisted_state_flash_block, mut fields_flash_block] =
FlashBlockEsp::new_array::<2>(p.FLASH)?;
let wifi_persisted_state = wifi_persisted_state_flash_block.load::<WifiPersistedState>()?;
if wifi_persisted_state.is_none() {
let wifi_persisted_state = WifiPersistedState {
ssid: heapless::String::new(),
password: heapless::String::new(),
timezone_offset_minutes: 0,
};
wifi_persisted_state_flash_block.save(&wifi_persisted_state)?;
}
fields_flash_block.clear()?;Implementations§
Source§impl FlashBlockEsp
impl FlashBlockEsp
Trait Implementations§
Source§impl Clone for FlashBlockEsp
impl Clone for FlashBlockEsp
Source§fn clone(&self) -> FlashBlockEsp
fn clone(&self) -> FlashBlockEsp
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
source. Read moreSource§impl FlashBlock for FlashBlockEsp
Available on target_os=none only.
impl FlashBlock for FlashBlockEsp
target_os=none only.