pub async fn fetch_all_items<'d, 'c, K: Key, S: NorFlash, CI: KeyCacheImpl<K>>(
flash: &'d mut S,
flash_range: Range<u32>,
cache: &'c mut CI,
data_buffer: &mut [u8],
) -> Result<MapItemIter<'d, 'c, K, S, CI>, Error<S::Error>>
Expand description
Get an iterator that iterates over all non-erased & non-corrupted items in the map.
You should be very careful when using the map item iterator:
- Because map doesn't erase the items when you insert a new one with the same key, so it's possible that the iterator returns items with the same key multiple times. Generally the last returned one is the `active` one.
- The iterator requires ALL items in the storage have the SAME type. If you have different types of items in your map, the iterator might return incorrect data or error.
The following is a simple example of how to use the iterator:
let mut flash = init_flash();
let flash_range = 0x1000..0x3000;
let mut data_buffer = [0; 128];
let mut cache = NoCache::new();
// Create the iterator of map items
let mut iterator = fetch_all_items::<u8, _, _>(
&mut flash,
flash_range.clone(),
&mut cache,
&mut data_buffer
)
.await
.unwrap();
let mut all_items = HashMap::new();
// Iterate through all items, suppose the Key and Value types are u8, u32
while let Some((key, value)) = iterator
.next::<u32>(&mut data_buffer)
.await
.unwrap()
{
// Do somethinmg with the item.
// Please note that for the same key there might be multiple items returned,
// the last one is the current active one.
all_items.insert(key, value);
}