pub struct WriteHandle<T, A: Allocator = Global> { /* private fields */ }allocator_api only.Expand description
The writer for a Stele
This is the only type capable of writing to the underlying Stele and so some limitaions are in place:
§Why is
WriteHandleSend but !Sync?
This must be !Sync because while you can safely reserve a slot to avoid write-write conflicts
in any one memory location using fetch_add,
there can still be a race where a concurrent push while a previous push is still allocating can
segfault as readers can see the new length before memory is written.
§Why can I only append?
Append-only concurrent data structures avoid a major problem in the concurrent data structure space: Memory Reclamation. By only allowing appending elements and not mutation or removal, there cannot be a read-write data race, and all data is reclaimed if and only if there are no more handles left, at which point there cannot be any way to access the data inside and therefore we leave no dangling references.
Implementations§
Source§impl<T, A: Allocator> WriteHandle<T, A>
impl<T, A: Allocator> WriteHandle<T, A>
Sourcepub fn push(&self, val: T)
pub fn push(&self, val: T)
Pushes a new item on to the end of the Stele, allocating a new block of memory if necessary
Sourcepub fn new_read_handle(&self) -> ReadHandle<T, A>
pub fn new_read_handle(&self) -> ReadHandle<T, A>
Creates a new ReadHandle
Sourcepub fn read(&self, idx: usize) -> &T
pub fn read(&self, idx: usize) -> &T
Reads the value at the given index
§Panic
This function panics in debug if the given index is out of bounds
Sourcepub fn len(&self) -> usize
pub fn len(&self) -> usize
Returns the current length of the underlying Stele
Note:
By calling this through the WriteHandle, you hold the only handle that can change the
length and therefore this information is accurate until the next call to push
Sourcepub fn is_empty(&self) -> bool
pub fn is_empty(&self) -> bool
Returns if the underlying Stele is empty
Note:
By calling this through the WriteHandle, you hold the only handle that can change the
length and therefore this information is accurate until the first call to push if it
returned true, and will remain accurate again after that as a Stele cannot remove elements