Skip to content

Commit 4f82b9b

Browse files
committed
Fix format
1 parent e3fe0a4 commit 4f82b9b

1 file changed

Lines changed: 17 additions & 14 deletions

File tree

src/nvs.rs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -34,37 +34,37 @@ pub struct NvsDefault(());
3434

3535
/// A specialized key-value storage wrapper around `EspNvs` that provides a simplified interface
3636
/// for storing and retrieving arbitrary data as byte arrays.
37-
///
37+
///
3838
/// This struct was introduced to solve issue [#585](https://github.com/esp-rs/esp-idf-svc/issues/585)
3939
/// where the `contains()` method in `EspNvs` incorrectly returned `false` for string values
4040
/// that actually existed in NVS partitions. The root cause was that `EspNvs` implements
4141
/// two different storage strategies:
42-
///
42+
///
4343
/// 1. **Native ESP-IDF NVS API**: Direct access to ESP-IDF's native types (u8, u16, u32, u64, i8, i16, i32, i64, str, blob)
4444
/// 2. **Serialized storage**: Everything stored as either u64 (≤7 bytes) or blob (>7 bytes) for compatibility with serde
45-
///
45+
///
4646
/// `EspKeyValueStorage` focuses on the second approach, providing a clean interface for:
4747
/// - Storing any data that can be represented as `&[u8]`
4848
/// - Automatic optimization: values ≤7 bytes stored as u64, larger values as blobs
4949
/// - Consistent `contains()` method that works correctly with this storage strategy
5050
/// - Full compatibility with Rust serde implementations (postcard, json, etc.)
51-
///
51+
///
5252
/// ## Usage
53-
///
53+
///
5454
/// ```rust,no_run
5555
/// use esp_idf_svc::nvs::{EspDefaultNvsPartition, EspKeyValueStorage};
56-
///
56+
///
5757
/// # fn main() -> Result<(), Box<dyn std::error::Error>> {
5858
/// let partition = EspDefaultNvsPartition::take()?;
5959
/// let storage = EspKeyValueStorage::new(partition, "my_namespace", true)?;
60-
///
60+
///
6161
/// // Store data as bytes
6262
/// let data = b"hello world";
6363
/// storage.set_raw("my_key", data)?;
64-
///
64+
///
6565
/// // Check if key exists (this works correctly, unlike the original EspNvs bug)
6666
/// assert!(storage.contains("my_key")?);
67-
///
67+
///
6868
/// // Retrieve data
6969
/// let mut buffer = [0u8; 64];
7070
/// if let Some(retrieved) = storage.get_raw("my_key", &mut buffer)? {
@@ -73,9 +73,9 @@ pub struct NvsDefault(());
7373
/// # Ok(())
7474
/// # }
7575
/// ```
76-
///
76+
///
7777
/// ## Performance Characteristics
78-
///
78+
///
7979
/// - **Small values (≤7 bytes)**: Stored as u64 for efficiency
8080
/// - **Large values (>7 bytes)**: Stored as ESP-IDF blobs
8181
/// - **Memory efficient**: No unnecessary allocations for small values
@@ -411,7 +411,7 @@ impl<T: NvsPartitionId> EspNvs<T> {
411411
Ok(Self(partition, handle))
412412
}
413413

414-
pub fn contains(&self, name:&str) -> Result<bool, EspError> {
414+
pub fn contains(&self, name: &str) -> Result<bool, EspError> {
415415
let c_key = to_cstring_arg(name)?;
416416
let mut entry_type: nvs_type_t = nvs_type_t_NVS_TYPE_ANY;
417417

@@ -426,7 +426,11 @@ impl<T: NvsPartitionId> EspNvs<T> {
426426
}
427427
}
428428

429-
pub fn contains_key_of_type(&self, name:&str, data_type: NvsDataType) -> Result<bool, EspError> {
429+
pub fn contains_key_of_type(
430+
&self,
431+
name: &str,
432+
data_type: NvsDataType,
433+
) -> Result<bool, EspError> {
430434
let c_key = to_cstring_arg(name)?;
431435
let mut entry_type: nvs_type_t = nvs_type_t_NVS_TYPE_ANY;
432436

@@ -823,7 +827,6 @@ impl<T: NvsPartitionId> RawStorage for EspNvs<T> {
823827
}
824828
}
825829

826-
827830
impl<T: NvsPartitionId> EspKeyValueStorage<T> {
828831
pub fn new(
829832
partition: EspNvsPartition<T>,

0 commit comments

Comments
 (0)