Skip to main content

ExactParallelSink

Trait ExactParallelSink 

Source
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§

Source

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§

Source

type Item: Send

The type of items that this parallel sink collects.

Required Methods§

Source

fn new(len: usize) -> Self

Creates a new sink able to collect the given number of items.

Source

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 the 0..len range,
  • each index in 0..len must be present at most once in all indices passed to calls to push_item() and ranges passed to calls to skip_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.

Source

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:

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.

Source

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>

Source§

impl<T: Send, const N: usize> ExactParallelSink for ArrayParallelSink<T, N>

Available on crate feature nightly only.