Nvs

Struct Nvs 

Source
pub struct Nvs<'a, T>
where 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<'a, T> Nvs<'a, T>
where T: Platform,

Source

pub fn new( partition_offset: usize, partition_size: usize, hal: &'a mut T, ) -> Result<Nvs<'a, 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<'a, 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<'a, 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 delete(&mut self, namespace: &Key, key: &Key) -> Result<(), Error>

Delete a key

Ignores missing keys or the namespaces

Source

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

Returns detailed statistics about the NVS partition usage

Auto Trait Implementations§

§

impl<'a, T> Freeze for Nvs<'a, T>

§

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

§

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

§

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

§

impl<'a, T> Unpin for Nvs<'a, T>

§

impl<'a, T> !UnwindSafe for Nvs<'a, T>

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.