pub trait ExactParallelSink {
type Item: Send;
const NEEDS_CLEANUP: bool;
// Required methods
fn new(len: usize) -> Self;
unsafe fn push_item(&self, index: usize, item: Self::Item);
unsafe fn skip_item_range(&self, range: Range<usize>);
unsafe fn cancel(self);
}Expand description
A sink to collect items in parallel.
You most likely won’t need to interact with this trait directly, as it is an
associated type of the FromExactParallelSink trait, itself used to
express output types of the
collect() and
try_collect() adaptors on
BaseExactParallelIterator. You can
however implement this trait if you want to allow your types to be collected
by these adaptors.
Required Associated Constants§
Sourceconst NEEDS_CLEANUP: bool
const NEEDS_CLEANUP: bool
Set to false if the skip function is guaranteed to be a noop.
Typically, skipping is a noop when std::mem::needs_drop() returns
false for the Item type.
Required Associated Types§
Required Methods§
Sourceunsafe fn push_item(&self, index: usize, item: Self::Item)
unsafe fn push_item(&self, index: usize, item: Self::Item)
Pushes the given item at the given index of this sink.
§Safety
Given the length len passed to the new() call that
initialized this sink:
- indices passed to
push_item()must be in the0..lenrange, - each index in
0..lenmust be present at most once in all indices passed to calls topush_item()and ranges passed to calls toskip_item_range().
It is therefore undefined behavior to call this function twice with the
same index, with an index contained in a range for which
skip_item_range() was invoked, etc.
You normally shouldn’t have to worry about this, because this API is
intended to be called by Paralight’s internal multi-threading engine.
This API is public to allow others to implement parallel sinks: when
implementing your own sink(s), you can rely on these unsafe
pre-conditions.
Sourceunsafe fn skip_item_range(&self, range: Range<usize>)
unsafe fn skip_item_range(&self, range: Range<usize>)
Indicates that the items in the given range won’t be pushed.
§Safety
Given the length len passed to the new() call that
initialized this sink:
- ranges passed to
skip_item_range()must be included in the0..lenrange, - each index in
0..lenmust be present at most once in all indices passed to calls topush_item()and ranges passed to calls toskip_item_range().
It is therefore undefined behavior to call this function twice with the
same range, with overlapping ranges, with a range that contains an
index for which push_item() was invoked, etc.
You normally shouldn’t have to worry about this, because this API is
intended to be called by Paralight’s internal multi-threading engine.
This API is public to allow others to implement parallel sinks: when
implementing your own sink(s), you can rely on these unsafe
pre-conditions.
Sourceunsafe fn cancel(self)
unsafe fn cancel(self)
Cancel and cleanup this sink.
The purpose of this function is to properly cleanup the sink during unwinding if a panic occured before all items have been pushed.
§Safety
This can only be called after all indices have been passed once and only
once to push_item() and
skip_item_range().
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety", so this trait is not object safe.
Implementors§
Source§impl<T: Send> ExactParallelSink for VecParallelSink<T>
impl<T: Send> ExactParallelSink for VecParallelSink<T>
Source§impl<T: Send, const N: usize> ExactParallelSink for ArrayParallelSink<T, N>
Available on crate feature nightly only.
impl<T: Send, const N: usize> ExactParallelSink for ArrayParallelSink<T, N>
nightly only.