Expand description
A single-producer multiple-consumer append-only fixed capacity array.
Creating a OnceArrayWriter<T> allocates a fixed-capacity buffer and
represents exclusive access to append elements. Any number of
Arc<OnceArray<T>> references can be created and shared across threads.
These readers can access the slice of committed elements, and see new
elements as they are committed by the writer without any locking.
OnceArray serves as a building block for streaming data to multiple
consumers while amortizing the cost of allocation and synchronization across
chunks of many elements.
§Example:
use once_array::{OnceArrayWriter, OnceArray};
let mut writer = OnceArrayWriter::with_capacity(1024);
// Clone the reader to share it across threads.
let reader1 = writer.reader().clone();
let reader2 = writer.reader().clone();
// Append some data to the writer.
writer.try_push(42).unwrap();
writer.try_push(43).unwrap();
// Commit the new elements to make them visible to readers.
writer.commit();
assert_eq!(reader1.as_slice(), &[42, 43]);
assert_eq!(reader2.as_slice(), &[42, 43]);Structs§
- Once
Array - The reader side of a single-producer multiple-consumer append-only fixed capacity array.
- Once
Array Writer - Exclusive write access to a
OnceArray.