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>
 
impl<T> ParallelVecWriter<T>
pub fn new(data: Vec<T>) -> Self
Sourcepub fn read_access(&self) -> impl Deref<Target = [T]> + '_
 
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.
Sourcepub fn unsafe_read_access(&self) -> UnsafeReadAccess<'_, T>
 
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.
Sourcepub fn with_index<R>(&self, idx: usize, f: impl FnOnce(&T) -> R) -> R
 
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.
Sourcepub fn with_slice<R>(&self, slice: Range<usize>, f: impl FnOnce(&[T]) -> R) -> R
 
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.
Sourcepub fn write_contents(&self, items: impl ExactSizeIterator<Item = T>) -> usize
 
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.