Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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