Struct MapItemIter

Source
pub struct MapItemIter<'d, 'c, S: NorFlash, CI: CacheImpl> { /* 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 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::<u8, 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);
}

Implementations§

Source§

impl<S: NorFlash, CI: CacheImpl> MapItemIter<'_, '_, S, CI>

Source

pub async fn next<'a, K: Key, 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<'d, 'c, S, CI> Freeze for MapItemIter<'d, 'c, S, CI>

§

impl<'d, 'c, S, CI> RefUnwindSafe for MapItemIter<'d, 'c, S, CI>

§

impl<'d, 'c, S, CI> Send for MapItemIter<'d, 'c, S, CI>
where S: Send, CI: Send,

§

impl<'d, 'c, S, CI> Sync for MapItemIter<'d, 'c, S, CI>
where S: Sync, CI: Sync,

§

impl<'d, 'c, S, CI> Unpin for MapItemIter<'d, 'c, S, CI>

§

impl<'d, 'c, S, CI> !UnwindSafe for MapItemIter<'d, 'c, S, CI>

Blanket Implementations§

Source§

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

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

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

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

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

Source§

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

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

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

Source§

fn into(self) -> U

Calls U::from(self).

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

Source§

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

Source§

type Error = Infallible

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

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

Performs the conversion.
Source§

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

Source§

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

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

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

Performs the conversion.