Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: support peek_many and pop_many #12

Merged
merged 10 commits into from
Dec 16, 2023
10 changes: 5 additions & 5 deletions src/item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ impl ItemHeader {
return Err(Error::BufferTooSmall(read_len));
}
if data_address + read_len as u32 > end_address {
return Ok(MaybeItem::Corrupted(self));
return Ok(MaybeItem::Corrupted(self, data_buffer));
}

flash
Expand All @@ -107,7 +107,7 @@ impl ItemHeader {
data_buffer,
}))
} else {
return Ok(MaybeItem::Corrupted(self));
return Ok(MaybeItem::Corrupted(self, data_buffer));
}
}
}
Expand Down Expand Up @@ -283,7 +283,7 @@ pub fn read_items<S: NorFlash, R>(
start_address,
end_address,
|flash, header, address| match header.read_item(flash, data_buffer, address, end_address) {
Ok(MaybeItem::Corrupted(_)) => {
Ok(MaybeItem::Corrupted(_, _)) => {
#[cfg(feature = "defmt")]
defmt::error!(
"Found a corrupted item at {:X}. Skipping...",
Expand Down Expand Up @@ -359,15 +359,15 @@ pub fn find_next_free_item_spot<S: NorFlash>(

#[derive(Debug)]
pub enum MaybeItem<'d> {
Corrupted(ItemHeader),
Corrupted(ItemHeader, &'d mut [u8]),
Erased(ItemHeader),
Present(Item<'d>),
}

impl<'d> MaybeItem<'d> {
pub fn unwrap<E>(self) -> Result<Item<'d>, Error<E>> {
match self {
MaybeItem::Corrupted(_) => Err(Error::Corrupted),
MaybeItem::Corrupted(_, _) => Err(Error::Corrupted),
MaybeItem::Erased(_) => panic!("Cannot unwrap an erased item"),
MaybeItem::Present(item) => Ok(item),
}
Expand Down
2 changes: 1 addition & 1 deletion src/map.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
//! A module for storing key-value pairs in flash with minimal erase cycles.
//!
//! When a key-value is stored, it overwrites the any old items with the same key.
//!
//!
//! Make sure to use the same [StorageItem] type on a given range in flash.
//! In theory you could use multiple types if you're careful, but they must at least have the same key definition and format.
//!
Expand Down
Loading