Skip to main content

Nvs

Struct Nvs 

Source
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>

Source

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

  1. Resolve all existing namespaces
  2. Create a hashed key cache per page for quicker lookups
  3. Cleanup duplicate entries
  4. Cleanup of duplicated blobs or orphaned blob data

Pages or entries with invalid CRC32 values are marked as corrupt and are erased when necessary

Source

pub fn get<R>(&mut self, namespace: &Key, key: &Key) -> Result<R, Error>
where Nvs<T>: Get<R>,

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.

Source

pub fn set<R>( &mut self, namespace: &Key, key: &Key, value: R, ) -> Result<(), Error>
where Nvs<T>: Set<R>,

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
Source

pub fn namespaces(&self) -> impl Iterator<Item = &Key>

Returns an iterator over all known namespaces.

Source

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.

Source

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.

Source

pub fn delete(&mut self, namespace: &Key, key: &Key) -> Result<(), Error>

Delete a key

Ignores missing keys or the namespaces

Source

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).

Source

pub fn statistics(&mut self) -> Result<NvsStatistics, Error>

Returns detailed statistics about the NVS partition usage

Trait Implementations§

Source§

impl<T: Platform> Get<String> for Nvs<T>

Source§

fn get(&mut self, namespace: &Key, key: &Key) -> Result<String, Error>

Source§

impl<T: Platform> Get<Vec<u8>> for Nvs<T>

Source§

fn get(&mut self, namespace: &Key, key: &Key) -> Result<Vec<u8>, Error>

Source§

impl<T: Platform> Get<bool> for Nvs<T>

Source§

fn get(&mut self, namespace: &Key, key: &Key) -> Result<bool, Error>

Source§

impl<T: Platform> Get<i16> for Nvs<T>

Source§

fn get(&mut self, namespace: &Key, key: &Key) -> Result<i16, Error>

Source§

impl<T: Platform> Get<i32> for Nvs<T>

Source§

fn get(&mut self, namespace: &Key, key: &Key) -> Result<i32, Error>

Source§

impl<T: Platform> Get<i64> for Nvs<T>

Source§

fn get(&mut self, namespace: &Key, key: &Key) -> Result<i64, Error>

Source§

impl<T: Platform> Get<i8> for Nvs<T>

Source§

fn get(&mut self, namespace: &Key, key: &Key) -> Result<i8, Error>

Source§

impl<T: Platform> Get<u16> for Nvs<T>

Source§

fn get(&mut self, namespace: &Key, key: &Key) -> Result<u16, Error>

Source§

impl<T: Platform> Get<u32> for Nvs<T>

Source§

fn get(&mut self, namespace: &Key, key: &Key) -> Result<u32, Error>

Source§

impl<T: Platform> Get<u64> for Nvs<T>

Source§

fn get(&mut self, namespace: &Key, key: &Key) -> Result<u64, Error>

Source§

impl<T: Platform> Get<u8> for Nvs<T>

Source§

fn get(&mut self, namespace: &Key, key: &Key) -> Result<u8, Error>

Source§

impl<T: Platform> Set<&[u8]> for Nvs<T>

Source§

fn set(&mut self, namespace: &Key, key: &Key, value: &[u8]) -> Result<(), Error>

Source§

impl<T: Platform> Set<&str> for Nvs<T>

Source§

fn set(&mut self, namespace: &Key, key: &Key, value: &str) -> Result<(), Error>

Source§

impl<T: Platform> Set<bool> for Nvs<T>

Source§

fn set(&mut self, namespace: &Key, key: &Key, value: bool) -> Result<(), Error>

Source§

impl<T: Platform> Set<i16> for Nvs<T>

Source§

fn set(&mut self, namespace: &Key, key: &Key, value: i16) -> Result<(), Error>

Source§

impl<T: Platform> Set<i32> for Nvs<T>

Source§

fn set(&mut self, namespace: &Key, key: &Key, value: i32) -> Result<(), Error>

Source§

impl<T: Platform> Set<i64> for Nvs<T>

Source§

fn set(&mut self, namespace: &Key, key: &Key, value: i64) -> Result<(), Error>

Source§

impl<T: Platform> Set<i8> for Nvs<T>

Source§

fn set(&mut self, namespace: &Key, key: &Key, value: i8) -> Result<(), Error>

Source§

impl<T: Platform> Set<u16> for Nvs<T>

Source§

fn set(&mut self, namespace: &Key, key: &Key, value: u16) -> Result<(), Error>

Source§

impl<T: Platform> Set<u32> for Nvs<T>

Source§

fn set(&mut self, namespace: &Key, key: &Key, value: u32) -> Result<(), Error>

Source§

impl<T: Platform> Set<u64> for Nvs<T>

Source§

fn set(&mut self, namespace: &Key, key: &Key, value: u64) -> Result<(), Error>

Source§

impl<T: Platform> Set<u8> for Nvs<T>

Source§

fn set(&mut self, namespace: &Key, key: &Key, value: u8) -> Result<(), Error>

Auto Trait Implementations§

§

impl<T> Freeze for Nvs<T>
where T: Freeze,

§

impl<T> RefUnwindSafe for Nvs<T>
where T: RefUnwindSafe,

§

impl<T> Send for Nvs<T>
where T: Send,

§

impl<T> Sync for Nvs<T>
where T: Sync,

§

impl<T> Unpin for Nvs<T>
where T: Unpin,

§

impl<T> UnsafeUnpin for Nvs<T>
where T: UnsafeUnpin,

§

impl<T> UnwindSafe for Nvs<T>
where T: UnwindSafe,

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.