Skip to main content

EspNvs

Struct EspNvs 

Source
pub struct EspNvs<T: NvsPartitionId>(/* private fields */);

Implementations§

Source§

impl<T: NvsPartitionId> EspNvs<T>

Source

pub fn new( partition: EspNvsPartition<T>, namespace: &str, read_write: bool, ) -> Result<Self, EspError>

Source

pub fn find_key(&self, name: &str) -> Result<Option<NvsDataType>, EspError>

Source

pub fn remove(&self, name: &str) -> Result<bool, EspError>

Source

pub fn blob_len(&self, name: &str) -> Result<Option<usize>, EspError>

Returns the length of the blob stored under the key name.

If the key does not exist, Ok(None) is returned.

§Errors
  • ESP_ERR_NVS_INVALID_HANDLE if the NVS handle is invalid.
  • ESP_ERR_NVS_INVALID_NAME if the key name is invalid.
Source

pub fn get_blob<'a>( &self, name: &str, buf: &'a mut [u8], ) -> Result<Option<&'a [u8]>, EspError>

Source

pub fn set_blob(&self, name: &str, buf: &[u8]) -> Result<(), EspError>

Source

pub fn str_len(&self, name: &str) -> Result<Option<usize>, EspError>

Returns the length of the string stored under the key name.

If the key does not exist, Ok(None) is returned.

§Errors
  • ESP_ERR_NVS_INVALID_HANDLE if the NVS handle is invalid.
  • ESP_ERR_NVS_INVALID_NAME if the key name is invalid.
§Note

The stored string is a [CString], which is why the returned length includes the null terminator.

Rust strings do not have a null terminator, so when constructing one, make sure to only use the bytes up to len - 1. Alternatively one can use [CStr] or [CString].

Source

pub fn get_str<'a>( &self, name: &str, buf: &'a mut [u8], ) -> Result<Option<&'a str>, EspError>

Source

pub fn set_str(&self, name: &str, val: &str) -> Result<(), EspError>

Source

pub fn get_u8(&self, name: &str) -> Result<Option<u8>, EspError>

Source

pub fn set_u8(&self, name: &str, val: u8) -> Result<(), EspError>

Source

pub fn get_i8(&self, name: &str) -> Result<Option<i8>, EspError>

Source

pub fn set_i8(&self, name: &str, val: i8) -> Result<(), EspError>

Source

pub fn get_u16(&self, name: &str) -> Result<Option<u16>, EspError>

Source

pub fn set_u16(&self, name: &str, val: u16) -> Result<(), EspError>

Source

pub fn get_i16(&self, name: &str) -> Result<Option<i16>, EspError>

Source

pub fn set_i16(&self, name: &str, val: i16) -> Result<(), EspError>

Source

pub fn get_u32(&self, name: &str) -> Result<Option<u32>, EspError>

Source

pub fn set_u32(&self, name: &str, val: u32) -> Result<(), EspError>

Source

pub fn get_i32(&self, name: &str) -> Result<Option<i32>, EspError>

Source

pub fn set_i32(&self, name: &str, val: i32) -> Result<(), EspError>

Source

pub fn get_u64(&self, name: &str) -> Result<Option<u64>, EspError>

Source

pub fn set_u64(&self, name: &str, val: u64) -> Result<(), EspError>

Source

pub fn get_i64(&self, name: &str) -> Result<Option<i64>, EspError>

Source

pub fn set_i64(&self, name: &str, val: i64) -> Result<(), EspError>

Source

pub fn erase_all(&self) -> Result<(), EspError>

Erases all key-value pairs in the NVS namespace.

§Errors

This function will return an error if the NVS erase operation fails, this can happen because of

  • a corrupted NVS partition
  • the NVS is opened in read-only mode
  • other internal errors from the underlying storage driver
Source

pub fn keys( &self, data_type: Option<NvsDataType>, ) -> Result<EspNvsKeys<'_>, EspError>

Returns struct to iterate over all keys stored in this NVS namespace with the specified data type.

A data type of None will return all keys regardless of their type.

§Mutating the NVS while iterating

Both this function and others that mutate the NVS like EspNvs::remove only require an immutable reference, making it possible to mutate the NVS while iterating over it. For example, one could remove keys while iterating.

It is not recommended to do this, because the iterator might skip keys. It will not result in a panic or undefinied behavior.

§Errors

This function will return an error if

  • there is no memory available for allocation of internal structures
  • for some reason the EspNvs::handle is invalid (should not happen)

Trait Implementations§

Source§

impl<T: NvsPartitionId> Drop for EspNvs<T>

Source§

fn drop(&mut self)

Executes the destructor for this type. Read more
§

fn pin_drop(self: Pin<&mut Self>)

🔬This is a nightly-only experimental API. (pin_ergonomics)
Execute the destructor for this type, but different to Drop::drop, it requires self to be pinned. Read more
Source§

impl RawHandle for EspNvs<NvsCustom>

Source§

type Handle = u32

Source§

fn handle(&self) -> Self::Handle

Care should be taken to use the returned ESP-IDF driver raw handle only while the driver is still alive, so as to avoid use-after-free errors.
Source§

impl RawHandle for EspNvs<NvsEncrypted>

Source§

type Handle = u32

Source§

fn handle(&self) -> Self::Handle

Care should be taken to use the returned ESP-IDF driver raw handle only while the driver is still alive, so as to avoid use-after-free errors.
Source§

impl RawHandle for EspNvs<NvsDefault>

Source§

type Handle = u32

Source§

fn handle(&self) -> Self::Handle

Care should be taken to use the returned ESP-IDF driver raw handle only while the driver is still alive, so as to avoid use-after-free errors.
Source§

impl<T: NvsPartitionId> Send for EspNvs<T>

Auto Trait Implementations§

§

impl<T> Freeze for EspNvs<T>
where EspNvsPartition<T>: Freeze,

§

impl<T> RefUnwindSafe for EspNvs<T>
where EspNvsPartition<T>: RefUnwindSafe,

§

impl<T> Sync for EspNvs<T>
where EspNvsPartition<T>: Sync,

§

impl<T> Unpin for EspNvs<T>
where EspNvsPartition<T>: Unpin,

§

impl<T> UnsafeUnpin for EspNvs<T>
where EspNvsPartition<T>: UnsafeUnpin,

§

impl<T> UnwindSafe for EspNvs<T>
where EspNvsPartition<T>: UnwindSafe,

Blanket Implementations§

§

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

§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
§

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

§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
§

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

§

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

Mutably borrows from an owned value. Read more
§

impl<T> From<T> for T

§

fn from(t: T) -> T

Returns the argument unchanged.

§

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

§

fn into(self) -> U

Calls U::from(self).

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

§

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

§

type Error = !

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

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
§

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

§

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

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

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

Performs the conversion.