pub struct Nvs<T: Platform> { /* private fields */ }Expand description
The Nvs struct keeps information about all pages in memory. Increases in size with the numer of pages in the partition.
Implementations§
Source§impl<T: Platform> Nvs<T>
impl<T: Platform> Nvs<T>
Sourcepub fn new(
partition_offset: usize,
partition_size: usize,
hal: T,
) -> Result<Nvs<T>, Error>
pub fn new( partition_offset: usize, partition_size: usize, hal: T, ) -> Result<Nvs<T>, Error>
Mimics the original C++ driver behavior and reads all sectors of the given partition to
- Resolve all existing namespaces
- Create a hashed key cache per page for quicker lookups
- Cleanup duplicate entries
- Cleanup of duplicated blobs or orphaned blob data
Pages or entries with invalid CRC32 values are marked as corrupt and are erased when necessary
Sourcepub fn get<R>(&mut self, namespace: &Key, key: &Key) -> Result<R, Error>
pub fn get<R>(&mut self, namespace: &Key, key: &Key) -> Result<R, Error>
Get a value from the flash.
Supported types are bool, singed and unsigned integers up to 64-bit width, String and Vec.
Both namespace and may have up to 15 characters.
Sourcepub fn set<R>(
&mut self,
namespace: &Key,
key: &Key,
value: R,
) -> Result<(), Error>
pub fn set<R>( &mut self, namespace: &Key, key: &Key, value: R, ) -> Result<(), Error>
Set a value and write it to the flash
Type support:
- bool, singed and unsigned integers up to 64-bit width: saved as primitive value with 32 bytes
- &str: Saved on a single page with a max size of 4000 bytes
- &u8: May span multiple pages, max size ~500kB
Sourcepub fn namespaces(&self) -> impl Iterator<Item = &Key>
pub fn namespaces(&self) -> impl Iterator<Item = &Key>
Returns an iterator over all known namespaces.
Sourcepub fn keys(&mut self) -> impl Iterator<Item = Result<(Key, Key), Error>>
pub fn keys(&mut self) -> impl Iterator<Item = Result<(Key, Key), Error>>
Returns an iterator over all keys in all namespaces.
§Errors
The iterator yields an error if there is a flash read error.
Sourcepub fn typed_entries(
&mut self,
) -> impl Iterator<Item = Result<(Key, Key, ItemType), Error>>
pub fn typed_entries( &mut self, ) -> impl Iterator<Item = Result<(Key, Key, ItemType), Error>>
Returns an iterator over all data entries with their types.
Each item yields (namespace_key, entry_key, item_type). Namespace
definition entries are skipped. For multi-chunk blobs, only a single
representative entry is returned (with type ItemType::BlobData).
Legacy single-page blobs are returned with type ItemType::Blob.
§Errors
The iterator yields an error if there is a flash read error.
Sourcepub fn delete(&mut self, namespace: &Key, key: &Key) -> Result<(), Error>
pub fn delete(&mut self, namespace: &Key, key: &Key) -> Result<(), Error>
Delete a key
Ignores missing keys or the namespaces
Sourcepub fn into_inner(self) -> T
pub fn into_inner(self) -> T
Consume the NVS instance and return the underlying platform / HAL.
This is useful for extracting the flash data after writing entries
(e.g. with mem_flash::MemFlash).
Sourcepub fn statistics(&mut self) -> Result<NvsStatistics, Error>
pub fn statistics(&mut self) -> Result<NvsStatistics, Error>
Returns detailed statistics about the NVS partition usage