Module mini_io_queue::storage
source · [−]Expand description
Types to define how data is stored in a queue.
To access data in an asyncio, blocking or nonblocking queue, the backing buffer must
implement the Storage trait. This trait acts as an unsafe building block to access
multiple mutable regions in a buffer, which each queue builds on to provide safe abstractions.
Two standard storage types are available out of the box:
HeapBufferstores a contiguous array of items on the heap. This means the buffer can have a size chosen at runtime and is cheaper to move, with the possible downside of requiring an allocator.StackBufferstores a contiguous array of items on the stack. As a result, it has a fixed size at compile-time and can be expensive to move but is extremely cheap to create.
Note: all queues currently move their buffers to the heap when constructed.
Examples
Creating a queue from a heap-allocated buffer:
use mini_io_queue::blocking;
use mini_io_queue::storage::HeapBuffer;
let buffer: HeapBuffer<u8> = HeapBuffer::new(100);
let (reader, writer) = blocking::queue_from(buffer);Creating a queue from a stack-allocated buffer:
use mini_io_queue::blocking;
use mini_io_queue::storage::StackBuffer;
let buffer: StackBuffer<u8, 100> = StackBuffer::default();
let (reader, writer) = blocking::queue_from(buffer);Structs
HeapBuffer
heap-bufferBacking buffer for a queue, allocated on the heap.
StackBuffer
stack-bufferBacking buffer for a queue, allocated on the stack.
Traits
Storage for a contiguous array of items allowing mutable access to multiple ranges as long as they don’t overlap.