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,
impl<'a, T> Nvs<'a, T>where
T: Platform,
Sourcepub fn new(
partition_offset: usize,
partition_size: usize,
hal: &'a mut T,
) -> Result<Nvs<'a, T>, Error>
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
- 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>where
Nvs<'a, T>: Get<R>,
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.
Sourcepub fn set<R>(
&mut self,
namespace: &Key,
key: &Key,
value: R,
) -> Result<(), Error>where
Nvs<'a, T>: Set<R>,
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
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 statistics(&mut self) -> Result<NvsStatistics, Error>
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> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more