pub trait ParExtendCore<T>: Extend<T> {
type ThreadValues: Send;
type OrderedThreadValues: Send;
Show 19 methods
// Required methods
fn new_thread_values() -> Self::ThreadValues;
fn new_ordered_thread_values() -> Self::OrderedThreadValues;
fn add_thread_value(collected: &mut Self::ThreadValues, value: T);
fn add_thread_values(
collected: &mut Self::ThreadValues,
values: impl IntoIterator<Item = T>,
);
fn add_ordered_thread_value(
collected: &mut Self::OrderedThreadValues,
idx: usize,
value: T,
);
fn add_ordered_thread_values(
collected: &mut Self::OrderedThreadValues,
idx: usize,
values: impl IntoIterator<Item = T>,
);
fn add_ordered_thread_optionals(
collected: &mut Self::OrderedThreadValues,
idx: usize,
values: impl IntoIterator<Item = Option<T>>,
) -> Option<()>;
fn add_ordered_thread_fallibles<E>(
collected: &mut Self::OrderedThreadValues,
idx: usize,
values: impl IntoIterator<Item = Result<T, E>>,
) -> Result<(), E>;
fn add_one(&mut self, value: T);
fn extend_merge_infallibles(
&mut self,
thread_results: Vec<Self::ThreadValues>,
);
fn extend_merge_ordered_infallibles(
&mut self,
thread_results: Vec<Self::OrderedThreadValues>,
);
// Provided methods
fn add_thread_optionals(
collected: &mut Self::ThreadValues,
values: impl IntoIterator<Item = Option<T>>,
) -> Option<()> { ... }
fn add_thread_fallibles<E>(
collected: &mut Self::ThreadValues,
values: impl IntoIterator<Item = Result<T, E>>,
) -> Result<(), E> { ... }
fn extend_optionals(
&mut self,
optionals: impl IntoIterator<Item = Option<T>>,
) -> Option<()> { ... }
fn extend_fallibles<E>(
&mut self,
fallibles: impl IntoIterator<Item = Result<T, E>>,
) -> Result<(), E> { ... }
fn extend_merge_optionals(
&mut self,
thread_results: Vec<Option<Self::ThreadValues>>,
) -> Option<()> { ... }
fn extend_merge_ordered_optionals(
&mut self,
thread_results: Vec<Option<Self::OrderedThreadValues>>,
) -> Option<()> { ... }
fn extend_merge_fallibles<E>(
&mut self,
thread_results: Vec<Result<Self::ThreadValues, E>>,
) -> Result<(), E> { ... }
fn extend_merge_ordered_fallibles<E>(
&mut self,
thread_results: Vec<Result<Self::OrderedThreadValues, E>>,
) -> Result<(), E> { ... }
}Expand description
Parallel collection support for destinations that must be populated from multiple worker threads.
ParExtend extends the standard Extend contract with the information needed to collect
values produced concurrently and merge them back into a single destination. This is the
abstraction used by the parallel iterators to assemble results without depending on a
specific collection type or on a legacy common trait implementation.
A destination can support either arbitrary-order collection or ordered collection. In the first case, each thread accumulates a local buffer and the final merge combines those buffers into the destination. In the second case, each thread keeps index-aware entries so the final merge can restore the original ordering.
This is intended for parallel collection from fallible, optional, and infallible item streams, while preserving the corresponding short-circuit semantics and merge behavior.
Required Associated Types§
Sourcetype ThreadValues: Send
type ThreadValues: Send
Per-thread accumulation buffer for arbitrary-order collection.
Sourcetype OrderedThreadValues: Send
type OrderedThreadValues: Send
Per-thread accumulation buffer for ordered collection, where the position of each emitted item is known by its original index.
Required Methods§
Sourcefn new_thread_values() -> Self::ThreadValues
fn new_thread_values() -> Self::ThreadValues
Creates an empty buffer for a single worker thread in arbitrary-order collection mode.
Sourcefn new_ordered_thread_values() -> Self::OrderedThreadValues
fn new_ordered_thread_values() -> Self::OrderedThreadValues
Creates an empty buffer for a single worker thread in ordered collection mode.
Sourcefn add_thread_value(collected: &mut Self::ThreadValues, value: T)
fn add_thread_value(collected: &mut Self::ThreadValues, value: T)
Adds a single value into a thread-local arbitrary-order buffer.
Sourcefn add_thread_values(
collected: &mut Self::ThreadValues,
values: impl IntoIterator<Item = T>,
)
fn add_thread_values( collected: &mut Self::ThreadValues, values: impl IntoIterator<Item = T>, )
Adds all values from an iterator into a thread-local arbitrary-order buffer.
Sourcefn add_ordered_thread_value(
collected: &mut Self::OrderedThreadValues,
idx: usize,
value: T,
)
fn add_ordered_thread_value( collected: &mut Self::OrderedThreadValues, idx: usize, value: T, )
Adds a single value at the given index to a thread-local ordered buffer.
Sourcefn add_ordered_thread_values(
collected: &mut Self::OrderedThreadValues,
idx: usize,
values: impl IntoIterator<Item = T>,
)
fn add_ordered_thread_values( collected: &mut Self::OrderedThreadValues, idx: usize, values: impl IntoIterator<Item = T>, )
Adds all values from an iterator into a thread-local ordered buffer, assigning the original indices to each entry.
Sourcefn add_ordered_thread_optionals(
collected: &mut Self::OrderedThreadValues,
idx: usize,
values: impl IntoIterator<Item = Option<T>>,
) -> Option<()>
fn add_ordered_thread_optionals( collected: &mut Self::OrderedThreadValues, idx: usize, values: impl IntoIterator<Item = Option<T>>, ) -> Option<()>
Consumes an iterator of optional values and stores only the Some items in a thread-local
ordered buffer.
Sourcefn add_ordered_thread_fallibles<E>(
collected: &mut Self::OrderedThreadValues,
idx: usize,
values: impl IntoIterator<Item = Result<T, E>>,
) -> Result<(), E>
fn add_ordered_thread_fallibles<E>( collected: &mut Self::OrderedThreadValues, idx: usize, values: impl IntoIterator<Item = Result<T, E>>, ) -> Result<(), E>
Consumes an iterator of fallible values and stores only the successful items in a thread-local ordered buffer.
Sourcefn extend_merge_infallibles(&mut self, thread_results: Vec<Self::ThreadValues>)
fn extend_merge_infallibles(&mut self, thread_results: Vec<Self::ThreadValues>)
Merges thread-local arbitrary-order results into the destination collection.
Sourcefn extend_merge_ordered_infallibles(
&mut self,
thread_results: Vec<Self::OrderedThreadValues>,
)
fn extend_merge_ordered_infallibles( &mut self, thread_results: Vec<Self::OrderedThreadValues>, )
Merges thread-local ordered results into the destination collection, restoring the original item order before the final collection is completed.
Provided Methods§
Sourcefn add_thread_optionals(
collected: &mut Self::ThreadValues,
values: impl IntoIterator<Item = Option<T>>,
) -> Option<()>
fn add_thread_optionals( collected: &mut Self::ThreadValues, values: impl IntoIterator<Item = Option<T>>, ) -> Option<()>
Consumes an iterator of optional values and stores only the Some items in a thread-local
arbitrary-order buffer.
Sourcefn add_thread_fallibles<E>(
collected: &mut Self::ThreadValues,
values: impl IntoIterator<Item = Result<T, E>>,
) -> Result<(), E>
fn add_thread_fallibles<E>( collected: &mut Self::ThreadValues, values: impl IntoIterator<Item = Result<T, E>>, ) -> Result<(), E>
Consumes an iterator of fallible values and stores only the successful items in a thread-local arbitrary-order buffer.
Sourcefn extend_optionals(
&mut self,
optionals: impl IntoIterator<Item = Option<T>>,
) -> Option<()>
fn extend_optionals( &mut self, optionals: impl IntoIterator<Item = Option<T>>, ) -> Option<()>
Extends the destination with optional items, stopping early if an Option::None is
encountered while preserving the short-circuit semantics used by the parallel APIs.
Sourcefn extend_fallibles<E>(
&mut self,
fallibles: impl IntoIterator<Item = Result<T, E>>,
) -> Result<(), E>
fn extend_fallibles<E>( &mut self, fallibles: impl IntoIterator<Item = Result<T, E>>, ) -> Result<(), E>
Extends the destination with fallible items, propagating the first error encountered.
Sourcefn extend_merge_optionals(
&mut self,
thread_results: Vec<Option<Self::ThreadValues>>,
) -> Option<()>
fn extend_merge_optionals( &mut self, thread_results: Vec<Option<Self::ThreadValues>>, ) -> Option<()>
Merges arbitrary-order optional thread results, returning None if any thread reported a
stop condition.
Sourcefn extend_merge_ordered_optionals(
&mut self,
thread_results: Vec<Option<Self::OrderedThreadValues>>,
) -> Option<()>
fn extend_merge_ordered_optionals( &mut self, thread_results: Vec<Option<Self::OrderedThreadValues>>, ) -> Option<()>
Merges ordered optional thread results, returning None if any thread reported a stop
condition.
Sourcefn extend_merge_fallibles<E>(
&mut self,
thread_results: Vec<Result<Self::ThreadValues, E>>,
) -> Result<(), E>
fn extend_merge_fallibles<E>( &mut self, thread_results: Vec<Result<Self::ThreadValues, E>>, ) -> Result<(), E>
Merges arbitrary-order fallible thread results, propagating the first error encountered.
Sourcefn extend_merge_ordered_fallibles<E>(
&mut self,
thread_results: Vec<Result<Self::OrderedThreadValues, E>>,
) -> Result<(), E>
fn extend_merge_ordered_fallibles<E>( &mut self, thread_results: Vec<Result<Self::OrderedThreadValues, E>>, ) -> Result<(), E>
Merges ordered fallible thread results, propagating the first error encountered while also restoring the original index ordering.
Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".