MapItemIter

Struct MapItemIter 

Source
pub struct MapItemIter<'s, K: Key, S: NorFlash, C: KeyCacheImpl<K>> { /* private fields */ }
Expand description

Iterator which iterates all non-erased & non-corrupted items in the map.

The iterator will return the (Key, Value) tuple when calling next(). If the iterator ends, it will return Ok(None).

The following is a simple example of how to use the iterator:


let mut flash = init_flash();

let mut storage = MapStorage::<u8, _, _>::new(flash, const { MapConfig::new(0x1000..0x3000) }, NoCache::new());
let mut data_buffer = [0; 128];

// Create the iterator of map items
let mut iterator = storage.fetch_all_items(
    &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 something 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);
}

Implementations§

Source§

impl<K: Key, S: NorFlash, C: KeyCacheImpl<K>> MapItemIter<'_, K, S, C>

Source

pub async fn next<'a, V: Value<'a>>( &mut self, data_buffer: &'a mut [u8], ) -> Result<Option<(K, V)>, Error<S::Error>>

Get the next item in the iterator. Be careful that the given data_buffer should large enough to contain the serialized key and value.

Auto Trait Implementations§

§

impl<'s, K, S, C> Freeze for MapItemIter<'s, K, S, C>

§

impl<'s, K, S, C> RefUnwindSafe for MapItemIter<'s, K, S, C>

§

impl<'s, K, S, C> Send for MapItemIter<'s, K, S, C>
where K: Send, S: Send, C: Send,

§

impl<'s, K, S, C> Sync for MapItemIter<'s, K, S, C>
where K: Sync, S: Sync, C: Sync,

§

impl<'s, K, S, C> Unpin for MapItemIter<'s, K, S, C>
where K: Unpin,

§

impl<'s, K, S, C> !UnwindSafe for MapItemIter<'s, K, S, C>

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 = Infallible

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

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

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.