ParallelVecWriter

Struct ParallelVecWriter 

Source
pub struct ParallelVecWriter<T> { /* private fields */ }
Expand description

A struct that wraps a vector and allows for parallel writes to it.

While the writes happen, reads to the vector can proceed without being blocked by writes (except during a vector resize). The final vector can be extracted using the finish method. Elements written to the vector behind a ParallelVecWriter will not be dropped unless finish is called.

Implementations§

Source§

impl<T> ParallelVecWriter<T>

Source

pub fn new(data: Vec<T>) -> Self

Source

pub fn read_access(&self) -> impl Deref<Target = [T]> + '_

Get read access to the portion of the vector that was present before the ParallelVecWriter was created. Unlike the with_ methods, callers should be careful about keeping the object returned from this method around for too long.

Source

pub fn unsafe_read_access(&self) -> UnsafeReadAccess<'_, T>

Get unsafe read access to the vector.

This handle allows for reads past the end of the wrapped vector. Callers must guarantee that any cells read are covered by a corresponding call to ParallelVecWriter::write_contents.

Source

pub fn with_index<R>(&self, idx: usize, f: impl FnOnce(&T) -> R) -> R

Runs f with access to the element at idx.

§Panics

This method panics if idx is greater than or equal to the length of the vector when the ParallelVecWriter was created.

Source

pub fn with_slice<R>(&self, slice: Range<usize>, f: impl FnOnce(&[T]) -> R) -> R

Runs f with access to the slice of elements in the range slice.

§Panics

This method panics if slice.end is greater than or equal to the length of the vector when the ParallelVecWriter was created.

Source

pub fn write_contents(&self, items: impl ExactSizeIterator<Item = T>) -> usize

Write the contents of items to a contiguous chunk of the vector, returning the index of the first element in items.

Panics It is very important that items does not lie about its length. This method panics if the actual length does not match the length method.

Source

pub fn finish(self) -> Vec<T>

Source

pub fn take(&mut self) -> Vec<T>

Auto Trait Implementations§

§

impl<T> !Freeze for ParallelVecWriter<T>

§

impl<T> !RefUnwindSafe for ParallelVecWriter<T>

§

impl<T> Send for ParallelVecWriter<T>
where T: Send,

§

impl<T> Sync for ParallelVecWriter<T>
where T: Send,

§

impl<T> Unpin for ParallelVecWriter<T>
where T: Unpin,

§

impl<T> UnwindSafe for ParallelVecWriter<T>
where T: UnwindSafe,

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.