pub fn queue_from_parts<S>(ring: Ring, storage: S) -> (Reader<S>, Writer<S>)
Available on crate feature
asyncio
only.Expand description
Creates a queue from a separately allocated ring and storage. The queue will use the ring’s capacity, and be initialized with a read buffer from the ring’s left region and a write buffer from the ring’s right region.
It is up to the user to ensure the storage has enough capacity for the ring. If the ring’s capacity is larger than the storage’s length, the reader and writer may panic.
Note that the reader and writer will only implement Send
and Sync
if the storage also
does.
§Example
use mini_io_queue::Ring;
use mini_io_queue::asyncio::queue_from_parts;
use mini_io_queue::storage::{HeapBuffer, Storage};
// Create a queue with half of the underlying buffer in the read side.
let ring = Ring::new(10);
ring.advance_right(5);
let mut buffer = HeapBuffer::new(10);
buffer.slice_mut(0..5).copy_from_slice(&[1, 2, 3, 4, 5]);
let (reader, writer) = queue_from_parts(ring, buffer);