pub struct EspNvs<T: NvsPartitionId>(/* private fields */);Implementations§
Source§impl<T: NvsPartitionId> EspNvs<T>
impl<T: NvsPartitionId> EspNvs<T>
pub fn new( partition: EspNvsPartition<T>, namespace: &str, read_write: bool, ) -> Result<Self, EspError>
pub fn find_key(&self, name: &str) -> Result<Option<NvsDataType>, EspError>
pub fn remove(&self, name: &str) -> Result<bool, EspError>
Sourcepub fn blob_len(&self, name: &str) -> Result<Option<usize>, EspError>
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_HANDLEif the NVS handle is invalid.ESP_ERR_NVS_INVALID_NAMEif the key name is invalid.
pub fn get_blob<'a>( &self, name: &str, buf: &'a mut [u8], ) -> Result<Option<&'a [u8]>, EspError>
pub fn set_blob(&self, name: &str, buf: &[u8]) -> Result<(), EspError>
Sourcepub fn str_len(&self, name: &str) -> Result<Option<usize>, EspError>
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_HANDLEif the NVS handle is invalid.ESP_ERR_NVS_INVALID_NAMEif 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].
pub fn get_str<'a>( &self, name: &str, buf: &'a mut [u8], ) -> Result<Option<&'a str>, EspError>
pub fn set_str(&self, name: &str, val: &str) -> Result<(), EspError>
pub fn get_u8(&self, name: &str) -> Result<Option<u8>, EspError>
pub fn set_u8(&self, name: &str, val: u8) -> Result<(), EspError>
pub fn get_i8(&self, name: &str) -> Result<Option<i8>, EspError>
pub fn set_i8(&self, name: &str, val: i8) -> Result<(), EspError>
pub fn get_u16(&self, name: &str) -> Result<Option<u16>, EspError>
pub fn set_u16(&self, name: &str, val: u16) -> Result<(), EspError>
pub fn get_i16(&self, name: &str) -> Result<Option<i16>, EspError>
pub fn set_i16(&self, name: &str, val: i16) -> Result<(), EspError>
pub fn get_u32(&self, name: &str) -> Result<Option<u32>, EspError>
pub fn set_u32(&self, name: &str, val: u32) -> Result<(), EspError>
pub fn get_i32(&self, name: &str) -> Result<Option<i32>, EspError>
pub fn set_i32(&self, name: &str, val: i32) -> Result<(), EspError>
pub fn get_u64(&self, name: &str) -> Result<Option<u64>, EspError>
pub fn set_u64(&self, name: &str, val: u64) -> Result<(), EspError>
pub fn get_i64(&self, name: &str) -> Result<Option<i64>, EspError>
pub fn set_i64(&self, name: &str, val: i64) -> Result<(), EspError>
Sourcepub fn erase_all(&self) -> Result<(), EspError>
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
Sourcepub fn keys(
&self,
data_type: Option<NvsDataType>,
) -> Result<EspNvsKeys<'_>, EspError>
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::handleis invalid (should not happen)