Sequential-storage

crates.io Documentation

A crate for storing key-value pairs in flash with minimal erase cycles.

Basic API:

```rust,ignore enum MyCustomType { X, Y, // ... }

impl StorageItem for MyCustomType { // ... }

let mut flash = SomeFlashChip::new(); let flash_range = 0x1000..0x2000; // These are the flash addresses in which the crate will operate

asserteq!( fetchitem::( &mut flash, flash_range.clone(), 0 ).unwrap(), None );

storeitem::( &mut flash, flashrange.clone(), MyCustomType::X ).unwrap();

asserteq!( fetchitem::( &mut flash, flash_range.clone(), 0 ).unwrap(), Some(MyCustomType::X) ); ```

TODO

Inner workings

The idea behind this crate it to save on flash erase cycles by storing every item in an append-only way. Only the most recent value of a key-value item is 'active'.

This is more efficient because we don't have to erase a page every time we want to update a value.

Every item has to fit in a page. Once an item is too big to fit on the current page will be closed and the item will be stored on the next page.

Once all pages have been closed, the next page will be erased to open it up again. There is the possibility that the erased page contains the only copy of a key, so the crate checks if that happens and if it does add that key-value item back in. In principle you will never lose any data.

Changelog

0.2.0 - 13-01-23