Module queue

Source
Expand description

A queue (fifo) implementation for storing arbitrary data in flash memory.

Use push to add data to the fifo and use peek and pop to get the data back.


// Initialize the flash. This can be internal or external
let mut flash = init_flash();
// These are the flash addresses in which the crate will operate.
// The crate will not read, write or erase outside of this range.
let flash_range = 0x1000..0x3000;
// We need to give the crate a buffer to work with.
// It must be big enough to serialize the biggest value of your storage type in.
let mut data_buffer = [0; 128];

let my_data = [10, 47, 29];

// We can push some data to the queue
push(&mut flash, flash_range.clone(), &mut NoCache::new(), &my_data, false).await.unwrap();

// We can peek at the oldest data

assert_eq!(
    &peek(&mut flash, flash_range.clone(), &mut NoCache::new(), &mut data_buffer).await.unwrap().unwrap()[..],
    &my_data[..]
);

// With popping we get back the oldest data, but that data is now also removed

assert_eq!(
    &pop(&mut flash, flash_range.clone(), &mut NoCache::new(), &mut data_buffer).await.unwrap().unwrap()[..],
    &my_data[..]
);

// If we pop again, we find there's no data anymore

assert_eq!(
    pop(&mut flash, flash_range.clone(), &mut NoCache::new(), &mut data_buffer).await,
    Ok(None)
);

Structs§

QueueIterator
An iterator-like interface for peeking into data stored in flash with the option to pop it.
QueueIteratorEntry
An entry in the iteration over the queue flash

Functions§

find_max_fit
Find the largest size of data that can be stored.
iter
Get an iterator-like interface to iterate over the items stored in the queue. This goes from oldest to newest.
peek
Peek at the oldest data.
pop
Pop the oldest data from the queue.
push
Push data into the queue in the given flash memory with the given range. The data can only be taken out with the pop function.
space_left
Calculate how much space is left free in the queue (in bytes).