WriteHandle

Struct WriteHandle 

Source
pub struct WriteHandle<T, A: Allocator = Global> { /* private fields */ }
Available on crate feature 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:

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>

Source

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

Source

pub fn new_read_handle(&self) -> ReadHandle<T, A>

Creates a new ReadHandle

Source

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

Source

pub fn try_read(&self, idx: usize) -> Option<&T>

Attempts to read the value at the index and returns Some if the value exists, and None otherwise

Source

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

Source

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

Source§

impl<T: Copy, A: Allocator> WriteHandle<T, A>

Source

pub fn get(&self, idx: usize) -> T

Get provides a way to get an owned copy of a value inside a Stele provided the T implements Copy

§Panic

This function panics in debug if the given index is out of bounds

Trait Implementations§

Source§

impl<T: Debug, A: Debug + Allocator> Debug for WriteHandle<T, A>

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl<T, A: Allocator> Send for WriteHandle<T, A>
where T: Send + Sync,

Auto Trait Implementations§

§

impl<T, A> Freeze for WriteHandle<T, A>

§

impl<T, A> RefUnwindSafe for WriteHandle<T, A>

§

impl<T, A = Global> !Sync for WriteHandle<T, A>

§

impl<T, A> Unpin for WriteHandle<T, A>

§

impl<T, A> UnwindSafe for WriteHandle<T, A>

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.