pub trait ParResult: Sized + ParResultCore {
Show 36 methods
// Required methods
fn runner<Q: ParRunner>(
self,
runner: Q,
) -> impl ParResult<Elem = Self::Elem, Error = Self::Error, Xap1 = Self::Xap1, M = Self::M, Xap2 = Self::Xap2, Input = Self::Input, Size = Self::Size>;
fn runner_with_diagnostics(
self,
) -> impl ParResult<Elem = Self::Elem, Error = Self::Error, Xap1 = Self::Xap1, M = Self::M, Xap2 = Self::Xap2, Input = Self::Input, Size = Self::Size>;
fn num_threads(self, num_threads: impl Into<NumThreads>) -> Self;
fn chunk_size(self, chunk_size: impl Into<ChunkSize>) -> Self;
fn iteration_order(self, collect: IterationOrder) -> Self;
fn map<Q, H>(
self,
h: H,
) -> impl ParResult<Elem = Q, Error = Self::Error, Xap1 = Self::Xap1, M = Self::M, Xap2 = MapOf<Self::Xap2, Q, H>, Input = Self::Input, Size = Self::Size>
where H: Fn(Self::Elem) -> Q + Copy + Send;
fn inspect<H>(
self,
h: H,
) -> impl ParResult<Elem = Self::Elem, Error = Self::Error, Xap1 = Self::Xap1, M = Self::M, Xap2 = InsOf<Self::Xap2, H>, Input = Self::Input, Size = Self::Size>
where H: Fn(&Self::Elem) + Copy + Send;
fn filter<H>(
self,
h: H,
) -> impl ParResult<Elem = Self::Elem, Error = Self::Error, Xap1 = Self::Xap1, M = Self::M, Xap2 = FilOf<Self::Xap2, H>, Input = Self::Input, Size = <Self::Size as SizePair>::ThenBin>
where H: Fn(&Self::Elem) -> bool + Copy + Send;
fn filter_map<Q, H>(
self,
h: H,
) -> impl ParResult<Elem = Q, Error = Self::Error, Xap1 = Self::Xap1, M = Self::M, Xap2 = FilMapOf<Self::Xap2, Q, H>, Input = Self::Input, Size = <Self::Size as SizePair>::ThenBin>
where H: Fn(Self::Elem) -> Option<Q> + Copy + Send;
fn flat_map<V, H>(
self,
h: H,
) -> impl ParResult<Elem = V::Item, Error = Self::Error, Xap1 = Self::Xap1, M = Self::M, Xap2 = FlatMapOf<Self::Xap2, V, H>, Input = Self::Input, Size = <Self::Size as SizePair>::ThenMany>
where V: IntoIterator,
H: Fn(Self::Elem) -> V + Copy + Send;
fn flatten(
self,
) -> impl ParResult<Elem = <Self::Elem as IntoIterator>::Item, Error = Self::Error, Xap1 = Self::Xap1, M = Self::M, Xap2 = FlattenOf<Self::Xap2>, Input = Self::Input, Size = <Self::Size as SizePair>::ThenMany>
where Self::Elem: IntoIterator;
fn size_hint(&self) -> (usize, Option<usize>);
fn first(self) -> Result<Option<Self::Elem>, Self::Error>
where Self::Elem: Send,
Self::Error: Send;
fn reduce<F>(self, f: F) -> Result<Option<Self::Elem>, Self::Error>
where F: Fn(Self::Elem, Self::Elem) -> Self::Elem + Send + Copy,
Self::Elem: Send,
Self::Error: Send;
fn collect_into<P>(self, dst: &mut P) -> Result<(), Self::Error>
where P: ParExtend<Self::Elem>,
Self::Elem: Send,
Self::Error: Send;
// Provided methods
fn use_new<U, F>(
self,
f: F,
) -> impl ParUseResult<Elem = Self::Elem, Error = Self::Error, Use = U, Xap1 = IdUse<Self::Xap1, U>, M = Self::M, Xap2 = IdUse<Self::Xap2, U>, Input = Self::Input, Size = Self::Size>
where U: Send,
F: Fn(usize) -> U + Sync { ... }
fn use_vec<U, F>(
self,
use_vec: &mut UseVec<U, F>,
) -> impl ParUseResult<Elem = Self::Elem, Error = Self::Error, Use = U, Xap1 = IdUse<Self::Xap1, U>, M = Self::M, Xap2 = IdUse<Self::Xap2, U>, Input = Self::Input, Size = Self::Size>
where U: Send,
F: Fn(usize) -> U + Sync { ... }
fn use_slice<'a, U>(
self,
slice: &'a mut [U],
) -> impl ParUseResult<Elem = Self::Elem, Error = Self::Error, Use = U, Xap1 = IdUse<Self::Xap1, U>, M = Self::M, Xap2 = IdUse<Self::Xap2, U>, Input = Self::Input, Size = Self::Size>
where U: Send + 'a { ... }
fn copied<'a, O>(
self,
) -> impl ParResult<Elem = O, Error = Self::Error, Xap1 = Self::Xap1, M = Self::M, Xap2 = MappedOf<Self::Xap2, FnCopied<'a, O>>, Input = Self::Input, Size = Self::Size>
where Self: ParResult<Elem = &'a O>,
O: Copy + 'a { ... }
fn cloned<'a, O>(
self,
) -> impl ParResult<Elem = O, Error = Self::Error, Xap1 = Self::Xap1, M = Self::M, Xap2 = MappedOf<Self::Xap2, FnCloned<'a, O>>, Input = Self::Input, Size = Self::Size>
where Self: ParResult<Elem = &'a O>,
O: Clone + 'a { ... }
fn len(&self) -> usize
where Self::Input: ExactSizeConcurrentIter,
Self: ParResult<Size = OneOne> { ... }
fn is_empty(&self) -> bool
where Self::Input: ExactSizeConcurrentIter,
Self: ParResult<Size = OneOne> { ... }
fn collect<P>(self) -> Result<P, Self::Error>
where P: ParExtend<Self::Elem> + Default,
Self::Elem: Send,
Self::Error: Send { ... }
fn all<F>(self, f: F) -> Result<bool, Self::Error>
where Self::Elem: Send,
F: Fn(&Self::Elem) -> bool + Sync,
Self::Error: Send { ... }
fn any<F>(self, f: F) -> Result<bool, Self::Error>
where Self::Elem: Send,
F: Fn(&Self::Elem) -> bool + Sync,
Self::Error: Send { ... }
fn count(self) -> Result<usize, Self::Error>
where Self::Elem: Send,
Self::Error: Send { ... }
fn find<F>(self, f: F) -> Result<Option<Self::Elem>, Self::Error>
where Self::Elem: Send,
F: Fn(&Self::Elem) -> bool + Sync,
Self::Error: Send { ... }
fn fold<B, I, F>(self, init: I, f: F) -> Result<Vec<B>, Self::Error>
where B: Send,
I: Fn() -> B + Sync,
F: Fn(&mut B, Self::Elem) + Copy + Send,
Self::Error: Send { ... }
fn for_each<F>(self, f: F) -> Result<(), Self::Error>
where F: Fn(Self::Elem) + Send + Copy,
Self::Error: Send { ... }
fn max(self) -> Result<Option<Self::Elem>, Self::Error>
where Self::Elem: Ord + Send,
Self::Error: Send { ... }
fn max_by<F>(self, f: F) -> Result<Option<Self::Elem>, Self::Error>
where Self::Elem: Send,
F: Fn(&Self::Elem, &Self::Elem) -> Ordering + Sync,
Self::Error: Send { ... }
fn max_by_key<B, F>(self, f: F) -> Result<Option<Self::Elem>, Self::Error>
where Self::Elem: Send,
B: Ord,
F: Fn(&Self::Elem) -> B + Sync,
Self::Error: Send { ... }
fn min(self) -> Result<Option<Self::Elem>, Self::Error>
where Self::Elem: Ord + Send,
Self::Error: Send { ... }
fn min_by<F>(self, f: F) -> Result<Option<Self::Elem>, Self::Error>
where Self::Elem: Send,
F: Fn(&Self::Elem, &Self::Elem) -> Ordering + Sync,
Self::Error: Send { ... }
fn min_by_key<B, F>(self, f: F) -> Result<Option<Self::Elem>, Self::Error>
where Self::Elem: Send,
B: Ord,
F: Fn(&Self::Elem) -> B + Sync,
Self::Error: Send { ... }
fn sum<S>(self) -> Result<S, Self::Error>
where Self::Elem: Sum<S>,
S: Send,
Self::Error: Send { ... }
}Expand description
Fallible parallel iterator over Result values.
ParResult represents pipelines where each element may fail with an error.
It is commonly created from Par with
into_fallible.
Conceptually, this is similar to using the ? operator in Rust:
both let you keep logic on the success path while failures short-circuit.
In ParResult, the success path works with plain T values (instead of
Result<T, E>), and the parallel computation stops when an error is
observed.
Related traits:
Parfor infallible pipelines,ParUseResultfor the same fallibility model with worker-local state.
§Examples
Parse and validate records in parallel.
use orx_parallel::*;
let records = ["3", "8", "21", "34"];
let validated: Result<Vec<usize>, _> = records
.into_par()
.map(|s| s.parse::<usize>())
.into_fallible()
.map(|x| x * 2)
.filter(|x| *x <= 70)
.collect();
assert_eq!(validated, Ok(vec![6, 16, 42, 68]));
let with_failure: Result<Vec<usize>, _> = ["3", "bad", "21", "34"]
.into_par()
.map(|s| s.parse::<usize>())
.into_fallible()
.map(|x| x * 2)
.collect();
assert!(with_failure.is_err());Required Methods§
Sourcefn runner<Q: ParRunner>(
self,
runner: Q,
) -> impl ParResult<Elem = Self::Elem, Error = Self::Error, Xap1 = Self::Xap1, M = Self::M, Xap2 = Self::Xap2, Input = Self::Input, Size = Self::Size>
fn runner<Q: ParRunner>( self, runner: Q, ) -> impl ParResult<Elem = Self::Elem, Error = Self::Error, Xap1 = Self::Xap1, M = Self::M, Xap2 = Self::Xap2, Input = Self::Input, Size = Self::Size>
Replaces the current parallel runner with runner.
§Examples
use orx_parallel::*;
let par = ["1", "2", "3"]
.into_par()
.map(|s| s.parse::<usize>())
.into_fallible();
let par = par.runner(Runner::fixed());
let out: Result<Vec<_>, _> = par.collect();
assert_eq!(out, Ok(vec![1, 2, 3]));Sourcefn runner_with_diagnostics(
self,
) -> impl ParResult<Elem = Self::Elem, Error = Self::Error, Xap1 = Self::Xap1, M = Self::M, Xap2 = Self::Xap2, Input = Self::Input, Size = Self::Size>
fn runner_with_diagnostics( self, ) -> impl ParResult<Elem = Self::Elem, Error = Self::Error, Xap1 = Self::Xap1, M = Self::M, Xap2 = Self::Xap2, Input = Self::Input, Size = Self::Size>
Wraps the current runner with diagnostics-enabled execution.
§Examples
use orx_parallel::*;
let par = ["1", "2", "3"]
.into_par()
.map(|s| s.parse::<usize>())
.into_fallible();
#[cfg(feature = "std")]
let par = par.runner_with_diagnostics();
let out: Result<Vec<_>, _> = par.collect();
assert_eq!(out, Ok(vec![1, 2, 3]));Sourcefn num_threads(self, num_threads: impl Into<NumThreads>) -> Self
fn num_threads(self, num_threads: impl Into<NumThreads>) -> Self
Sets the maximum number of worker threads for this computation.
This method configures the computation layer of the thread count decision. The actual number of threads used is determined by combining:
- Pool constraint (from
pool()method or default pool)- Already includes
ORX_NUM_THREADSenvironment variable constraint
- Already includes
- Computation constraint (this method)
- Your per-computation thread preference
- Input size constraint
- Cannot spawn more threads than input elements
The actual thread count is the minimum of all these constraints.
§Parameter Interpretation
Integer values map as follows:
0=>NumThreads::Auto(use all available threads, spawn only as needed)n > 0=>NumThreads::Max(n)(cap atnthreads)
§Thread Count Decision Logic
available = pool.max_num_threads() // Pool maximum (includes env variable)
requested = match num_threads {
0 | Auto => input_size.max(1), // Limited by input size
Max(n) => min(input_size, n), // Limited by input size and this param
};
actual_threads = min(requested, available)§Examples
use orx_parallel::*;
// Sequential execution
let out: Result<Vec<_>, _> = ["1", "2", "3"]
.into_par()
.map(|s| s.parse::<usize>())
.into_fallible()
.num_threads(1)
.collect();
assert_eq!(out, Ok(vec![1, 2, 3]));
// Cap at 4 threads
let out: Result<Vec<_>, _> = (1..1001)
.into_par()
.map(Ok::<_, String>)
.into_fallible()
.num_threads(4)
.collect();§See Also
NumThreads- Type for thread configurationthread_usage.md- Complete threading guide
Sourcefn chunk_size(self, chunk_size: impl Into<ChunkSize>) -> Self
fn chunk_size(self, chunk_size: impl Into<ChunkSize>) -> Self
Sets chunk size used when pulling items from the concurrent input.
§Examples
use orx_parallel::*;
let out: Result<Vec<_>, _> = ["1", "2", "3", "4"]
.into_par()
.map(|s| s.parse::<usize>())
.into_fallible()
.chunk_size(2)
.collect();
assert_eq!(out, Ok(vec![1, 2, 3, 4]));Sourcefn iteration_order(self, collect: IterationOrder) -> Self
fn iteration_order(self, collect: IterationOrder) -> Self
Sets iteration-order semantics for order-sensitive operations.
§Examples
use orx_parallel::*;
let ordered = (1..10_000)
.into_par()
.map(Ok::<_, &'static str>)
.into_fallible()
.iteration_order(IterationOrder::Ordered)
.find(|x| x % 3421 == 0);
assert_eq!(ordered, Ok(Some(3421)));Sourcefn map<Q, H>(
self,
h: H,
) -> impl ParResult<Elem = Q, Error = Self::Error, Xap1 = Self::Xap1, M = Self::M, Xap2 = MapOf<Self::Xap2, Q, H>, Input = Self::Input, Size = Self::Size>
fn map<Q, H>( self, h: H, ) -> impl ParResult<Elem = Q, Error = Self::Error, Xap1 = Self::Xap1, M = Self::M, Xap2 = MapOf<Self::Xap2, Q, H>, Input = Self::Input, Size = Self::Size>
Maps each successful element with closure h.
§Examples
use orx_parallel::*;
let out: Result<Vec<_>, _> = ["1", "2", "3"]
.into_par()
.map(|s| s.parse::<usize>())
.into_fallible()
.map(|x| 2 * x)
.collect();
assert_eq!(out, Ok(vec![2, 4, 6]));Sourcefn inspect<H>(
self,
h: H,
) -> impl ParResult<Elem = Self::Elem, Error = Self::Error, Xap1 = Self::Xap1, M = Self::M, Xap2 = InsOf<Self::Xap2, H>, Input = Self::Input, Size = Self::Size>
fn inspect<H>( self, h: H, ) -> impl ParResult<Elem = Self::Elem, Error = Self::Error, Xap1 = Self::Xap1, M = Self::M, Xap2 = InsOf<Self::Xap2, H>, Input = Self::Input, Size = Self::Size>
Runs h on each successful element and forwards it unchanged.
§Examples
use core::sync::atomic::{AtomicUsize, Ordering};
use orx_parallel::*;
let seen = AtomicUsize::new(0);
let out: Result<Vec<_>, _> = ["1", "2", "3", "4"]
.into_par()
.map(|s| s.parse::<usize>())
.into_fallible()
.inspect(|_| { seen.fetch_add(1, Ordering::Relaxed); })
.collect();
assert_eq!(out, Ok(vec![1, 2, 3, 4]));
assert_eq!(seen.load(Ordering::Relaxed), 4);Sourcefn filter<H>(
self,
h: H,
) -> impl ParResult<Elem = Self::Elem, Error = Self::Error, Xap1 = Self::Xap1, M = Self::M, Xap2 = FilOf<Self::Xap2, H>, Input = Self::Input, Size = <Self::Size as SizePair>::ThenBin>
fn filter<H>( self, h: H, ) -> impl ParResult<Elem = Self::Elem, Error = Self::Error, Xap1 = Self::Xap1, M = Self::M, Xap2 = FilOf<Self::Xap2, H>, Input = Self::Input, Size = <Self::Size as SizePair>::ThenBin>
Keeps successful elements satisfying predicate h.
§Examples
use orx_parallel::*;
let out: Result<Vec<_>, _> = ["1", "2", "3", "4", "5", "6"]
.into_par()
.map(|s| s.parse::<usize>())
.into_fallible()
.filter(|x| x % 2 == 1)
.collect();
assert_eq!(out, Ok(vec![1, 3, 5]));Sourcefn filter_map<Q, H>(
self,
h: H,
) -> impl ParResult<Elem = Q, Error = Self::Error, Xap1 = Self::Xap1, M = Self::M, Xap2 = FilMapOf<Self::Xap2, Q, H>, Input = Self::Input, Size = <Self::Size as SizePair>::ThenBin>
fn filter_map<Q, H>( self, h: H, ) -> impl ParResult<Elem = Q, Error = Self::Error, Xap1 = Self::Xap1, M = Self::M, Xap2 = FilMapOf<Self::Xap2, Q, H>, Input = Self::Input, Size = <Self::Size as SizePair>::ThenBin>
Maps and filters successful elements in a single pass.
§Examples
use orx_parallel::*;
let out: Result<Vec<_>, &'static str> = ["1", "x", "5"]
.into_par()
.map(Ok::<_, &'static str>)
.into_fallible()
.filter_map(|s| s.parse::<usize>().ok())
.collect();
assert_eq!(out, Ok(vec![1, 5]));Sourcefn flat_map<V, H>(
self,
h: H,
) -> impl ParResult<Elem = V::Item, Error = Self::Error, Xap1 = Self::Xap1, M = Self::M, Xap2 = FlatMapOf<Self::Xap2, V, H>, Input = Self::Input, Size = <Self::Size as SizePair>::ThenMany>
fn flat_map<V, H>( self, h: H, ) -> impl ParResult<Elem = V::Item, Error = Self::Error, Xap1 = Self::Xap1, M = Self::M, Xap2 = FlatMapOf<Self::Xap2, V, H>, Input = Self::Input, Size = <Self::Size as SizePair>::ThenMany>
Maps each successful element to an iterator and flattens one level.
§Examples
use orx_parallel::*;
let out: Result<Vec<_>, _> = ["1", "2", "3"]
.into_par()
.map(|s| s.parse::<usize>())
.into_fallible()
.flat_map(|x| [x, x + 10])
.collect();
assert_eq!(out, Ok(vec![1, 11, 2, 12, 3, 13]));Sourcefn flatten(
self,
) -> impl ParResult<Elem = <Self::Elem as IntoIterator>::Item, Error = Self::Error, Xap1 = Self::Xap1, M = Self::M, Xap2 = FlattenOf<Self::Xap2>, Input = Self::Input, Size = <Self::Size as SizePair>::ThenMany>where
Self::Elem: IntoIterator,
fn flatten(
self,
) -> impl ParResult<Elem = <Self::Elem as IntoIterator>::Item, Error = Self::Error, Xap1 = Self::Xap1, M = Self::M, Xap2 = FlattenOf<Self::Xap2>, Input = Self::Input, Size = <Self::Size as SizePair>::ThenMany>where
Self::Elem: IntoIterator,
Flattens one level of nested iterables on the success path.
§Examples
use orx_parallel::*;
let nested = vec![vec![1, 2], vec![3, 4]];
let out: Result<Vec<_>, &'static str> = nested
.into_par()
.map(Ok::<_, &'static str>)
.into_fallible()
.flatten()
.collect();
assert_eq!(out, Ok(vec![1, 2, 3, 4]));Sourcefn size_hint(&self) -> (usize, Option<usize>)
fn size_hint(&self) -> (usize, Option<usize>)
Returns a lower and optional upper bound on the number of successful output items.
The bounds follow the usual Iterator::size_hint convention.
The upper bound includes items that may be removed by filtering or short-circuiting.
§Examples
use orx_parallel::*;
let values = (0..4)
.into_par()
.map(Ok::<_, ()>)
.into_fallible()
.filter(|x| x % 2 == 0);
assert_eq!(values.size_hint(), (0, Some(4)));Sourcefn first(self) -> Result<Option<Self::Elem>, Self::Error>
fn first(self) -> Result<Option<Self::Elem>, Self::Error>
Returns the first successful item according to iteration order.
§Examples
use orx_parallel::*;
assert_eq!(["1", "2", "3"].into_par().map(|s| s.parse::<usize>()).into_fallible().first(), Ok(Some(1)));
assert_eq!(Vec::<&str>::new().into_par().map(|s| s.parse::<usize>()).into_fallible().first(), Ok(None));Sourcefn reduce<F>(self, f: F) -> Result<Option<Self::Elem>, Self::Error>
fn reduce<F>(self, f: F) -> Result<Option<Self::Elem>, Self::Error>
Reduces successful items into one value using f.
§Examples
use orx_parallel::*;
let ok = (1..6)
.into_par()
.map(Ok::<_, &'static str>)
.into_fallible()
.reduce(|a, b| a + b);
assert_eq!(ok, Ok(Some(15)));
let fail = ["1", "x", "3"]
.into_par()
.map(|s| s.parse::<usize>().map_err(|_| "parse"))
.into_fallible()
.reduce(|a, b| a + b);
assert_eq!(fail, Err("parse"));Sourcefn collect_into<P>(self, dst: &mut P) -> Result<(), Self::Error>
fn collect_into<P>(self, dst: &mut P) -> Result<(), Self::Error>
Collects successful items into dst.
§Examples
use orx_parallel::*;
let mut dst = vec![10usize];
let ok = ["0", "1", "2"]
.into_par()
.map(|s| s.parse::<usize>())
.into_fallible()
.collect_into(&mut dst);
assert_eq!(ok, Ok(()));
assert_eq!(dst, vec![10, 0, 1, 2]);Provided Methods§
Sourcefn use_new<U, F>(
self,
f: F,
) -> impl ParUseResult<Elem = Self::Elem, Error = Self::Error, Use = U, Xap1 = IdUse<Self::Xap1, U>, M = Self::M, Xap2 = IdUse<Self::Xap2, U>, Input = Self::Input, Size = Self::Size>
fn use_new<U, F>( self, f: F, ) -> impl ParUseResult<Elem = Self::Elem, Error = Self::Error, Use = U, Xap1 = IdUse<Self::Xap1, U>, M = Self::M, Xap2 = IdUse<Self::Xap2, U>, Input = Self::Input, Size = Self::Size>
Creates one mutable Use value per participating worker.
§Examples
use orx_parallel::*;
use rand::prelude::*;
use rand_chacha::ChaCha8Rng;
let out: Result<Vec<_>, _> = ["0", "1", "2", "3", "4", "5", "6", "7"]
.into_par()
.map(|s| s.parse::<usize>())
.into_fallible()
.use_new(|thread_idx| ChaCha8Rng::seed_from_u64(10 + thread_idx as u64))
.map(|rng, x| x + rng.random_range(0..10))
.collect();
assert_eq!(out.as_ref().map(Vec::len), Ok(8));Sourcefn use_vec<U, F>(
self,
use_vec: &mut UseVec<U, F>,
) -> impl ParUseResult<Elem = Self::Elem, Error = Self::Error, Use = U, Xap1 = IdUse<Self::Xap1, U>, M = Self::M, Xap2 = IdUse<Self::Xap2, U>, Input = Self::Input, Size = Self::Size>
fn use_vec<U, F>( self, use_vec: &mut UseVec<U, F>, ) -> impl ParUseResult<Elem = Self::Elem, Error = Self::Error, Use = U, Xap1 = IdUse<Self::Xap1, U>, M = Self::M, Xap2 = IdUse<Self::Xap2, U>, Input = Self::Input, Size = Self::Size>
Uses an externally-owned UseVec as worker-local state.
§Examples
use orx_parallel::*;
let mut sums = UseVec::new(|_| 0usize);
let result = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]
.into_par()
.map(|s| s.parse::<usize>())
.into_fallible()
.use_vec(&mut sums)
.for_each(|local, x| *local += x);
assert_eq!(result, Ok(()));
assert_eq!(sums.into_vec().into_iter().sum::<usize>(), 55);Sourcefn use_slice<'a, U>(
self,
slice: &'a mut [U],
) -> impl ParUseResult<Elem = Self::Elem, Error = Self::Error, Use = U, Xap1 = IdUse<Self::Xap1, U>, M = Self::M, Xap2 = IdUse<Self::Xap2, U>, Input = Self::Input, Size = Self::Size>where
U: Send + 'a,
fn use_slice<'a, U>(
self,
slice: &'a mut [U],
) -> impl ParUseResult<Elem = Self::Elem, Error = Self::Error, Use = U, Xap1 = IdUse<Self::Xap1, U>, M = Self::M, Xap2 = IdUse<Self::Xap2, U>, Input = Self::Input, Size = Self::Size>where
U: Send + 'a,
Uses a caller-provided mutable slice as worker-local mutable state.
§Examples
use orx_parallel::*;
let mut sums = vec![0usize; 4];
let result = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]
.into_par()
.map(|s| s.parse::<usize>())
.into_fallible()
.use_slice(&mut sums)
.for_each(|local, x| *local += x);
assert_eq!(result, Ok(()));
assert_eq!(sums.into_iter().sum::<usize>(), 55);§Panics
Panics if the input produces at least one element but slice is empty.
Sourcefn copied<'a, O>(
self,
) -> impl ParResult<Elem = O, Error = Self::Error, Xap1 = Self::Xap1, M = Self::M, Xap2 = MappedOf<Self::Xap2, FnCopied<'a, O>>, Input = Self::Input, Size = Self::Size>
fn copied<'a, O>( self, ) -> impl ParResult<Elem = O, Error = Self::Error, Xap1 = Self::Xap1, M = Self::M, Xap2 = MappedOf<Self::Xap2, FnCopied<'a, O>>, Input = Self::Input, Size = Self::Size>
Copies elements of a reference iterator on the success path.
§Examples
use orx_parallel::*;
let data = vec![1, 2, 3];
let out: Result<Vec<_>, &'static str> = data
.par()
.map(Ok::<_, &'static str>)
.into_fallible()
.copied()
.collect();
assert_eq!(out, Ok(vec![1, 2, 3]));Sourcefn cloned<'a, O>(
self,
) -> impl ParResult<Elem = O, Error = Self::Error, Xap1 = Self::Xap1, M = Self::M, Xap2 = MappedOf<Self::Xap2, FnCloned<'a, O>>, Input = Self::Input, Size = Self::Size>
fn cloned<'a, O>( self, ) -> impl ParResult<Elem = O, Error = Self::Error, Xap1 = Self::Xap1, M = Self::M, Xap2 = MappedOf<Self::Xap2, FnCloned<'a, O>>, Input = Self::Input, Size = Self::Size>
Clones elements of a reference iterator on the success path.
§Examples
use orx_parallel::*;
let data = vec!["a".to_string(), "b".to_string()];
let out: Result<Vec<_>, &'static str> = data
.par()
.map(Ok::<_, &'static str>)
.into_fallible()
.cloned()
.collect();
assert_eq!(out, Ok(vec!["a".to_string(), "b".to_string()]));Sourcefn len(&self) -> usizewhere
Self::Input: ExactSizeConcurrentIter,
Self: ParResult<Size = OneOne>,
fn len(&self) -> usizewhere
Self::Input: ExactSizeConcurrentIter,
Self: ParResult<Size = OneOne>,
Returns the exact number of output items.
Sourcefn is_empty(&self) -> boolwhere
Self::Input: ExactSizeConcurrentIter,
Self: ParResult<Size = OneOne>,
fn is_empty(&self) -> boolwhere
Self::Input: ExactSizeConcurrentIter,
Self: ParResult<Size = OneOne>,
Returns true when the parallel iterator has no output items.
Sourcefn collect<P>(self) -> Result<P, Self::Error>
fn collect<P>(self) -> Result<P, Self::Error>
Collects successful items into a new collection.
§Examples
use orx_parallel::*;
let out: Result<Vec<_>, _> = ["1", "2", "3"]
.into_par()
.map(|s| s.parse::<usize>())
.into_fallible()
.collect();
assert_eq!(out, Ok(vec![1, 2, 3]));Sourcefn all<F>(self, f: F) -> Result<bool, Self::Error>
fn all<F>(self, f: F) -> Result<bool, Self::Error>
Returns Ok(true) if all successful items satisfy f.
Returns Err(e) on short-circuit failure.
§Examples
use orx_parallel::*;
let ok = ["1", "2", "3", "4"]
.into_par()
.map(|s| s.parse::<usize>())
.into_fallible()
.all(|x| x > &0);
assert_eq!(ok, Ok(true));Sourcefn any<F>(self, f: F) -> Result<bool, Self::Error>
fn any<F>(self, f: F) -> Result<bool, Self::Error>
Returns Ok(true) if any successful item satisfies f.
Returns Err(e) on short-circuit failure.
§Examples
use orx_parallel::*;
let ok = ["1", "2", "3", "4"]
.into_par()
.map(|s| s.parse::<usize>())
.into_fallible()
.any(|x| x % 2 == 0);
assert_eq!(ok, Ok(true));Sourcefn count(self) -> Result<usize, Self::Error>
fn count(self) -> Result<usize, Self::Error>
Counts successful elements.
Returns Err(e) on short-circuit failure.
§Examples
use orx_parallel::*;
let n = ["1", "2", "3", "4", "5", "6", "7", "8", "9", "10"]
.into_par()
.map(|s| s.parse::<usize>())
.into_fallible()
.filter(|x| x % 3 == 0)
.count();
assert_eq!(n, Ok(3));Sourcefn find<F>(self, f: F) -> Result<Option<Self::Elem>, Self::Error>
fn find<F>(self, f: F) -> Result<Option<Self::Elem>, Self::Error>
Finds first (ordered) or any (arbitrary) successful item satisfying f.
Returns Err(e) on short-circuit failure.
§Examples
use orx_parallel::*;
let numbers = (1..101).map(|x| x.to_string()).collect::<Vec<_>>();
let found = numbers
.into_par()
.map(|s| s.parse::<usize>())
.into_fallible()
.find(|x| x % 17 == 0);
assert_eq!(found, Ok(Some(17)));Sourcefn fold<B, I, F>(self, init: I, f: F) -> Result<Vec<B>, Self::Error>
fn fold<B, I, F>(self, init: I, f: F) -> Result<Vec<B>, Self::Error>
Folds successful elements into per-thread accumulators.
Returns Err(e) on short-circuit failure.
§Examples
use orx_parallel::*;
let partials = ["1", "2", "3", "4", "5"]
.into_par()
.map(|s| s.parse::<usize>())
.into_fallible()
.fold(|| 0usize, |acc, x| *acc += x)
.unwrap();
assert_eq!(partials.iter().sum::<usize>(), 15);Sourcefn for_each<F>(self, f: F) -> Result<(), Self::Error>
fn for_each<F>(self, f: F) -> Result<(), Self::Error>
Executes f for each successful element.
Returns Err(e) on short-circuit failure.
§Examples
use core::sync::atomic::{AtomicUsize, Ordering};
use orx_parallel::*;
let total = AtomicUsize::new(0);
let ok = ["1", "2", "3", "4"]
.into_par()
.map(|s| s.parse::<usize>())
.into_fallible()
.for_each(|x| {
total.fetch_add(x, Ordering::Relaxed);
});
assert_eq!(ok, Ok(()));
assert_eq!(total.load(Ordering::Relaxed), 10);Sourcefn max(self) -> Result<Option<Self::Elem>, Self::Error>
fn max(self) -> Result<Option<Self::Elem>, Self::Error>
Returns maximum successful element.
Returns Err(e) on short-circuit failure.
§Examples
use orx_parallel::*;
let m = ["1", "2", "3", "4"]
.into_par()
.map(|s| s.parse::<usize>())
.into_fallible()
.max();
assert_eq!(m, Ok(Some(4)));Sourcefn max_by<F>(self, f: F) -> Result<Option<Self::Elem>, Self::Error>
fn max_by<F>(self, f: F) -> Result<Option<Self::Elem>, Self::Error>
Returns successful element considered maximum by comparator f.
Returns Err(e) on short-circuit failure.
§Examples
use orx_parallel::*;
let x = vec![-3_i32, 0, 1, 5, -10]
.into_par()
.map(Ok::<_, &'static str>)
.into_fallible()
.max_by(|a, b| a.cmp(b));
assert_eq!(x, Ok(Some(5)));Sourcefn max_by_key<B, F>(self, f: F) -> Result<Option<Self::Elem>, Self::Error>
fn max_by_key<B, F>(self, f: F) -> Result<Option<Self::Elem>, Self::Error>
Returns successful element with maximum key value.
Returns Err(e) on short-circuit failure.
§Examples
use orx_parallel::*;
let x = vec![-3_i32, 0, 1, 5, -10]
.into_par()
.map(Ok::<_, &'static str>)
.into_fallible()
.max_by_key(|x| x.abs());
assert_eq!(x, Ok(Some(-10)));Sourcefn min(self) -> Result<Option<Self::Elem>, Self::Error>
fn min(self) -> Result<Option<Self::Elem>, Self::Error>
Returns minimum successful element.
Returns Err(e) on short-circuit failure.
§Examples
use orx_parallel::*;
let m = ["1", "2", "3", "4"]
.into_par()
.map(|s| s.parse::<usize>())
.into_fallible()
.min();
assert_eq!(m, Ok(Some(1)));Sourcefn min_by<F>(self, f: F) -> Result<Option<Self::Elem>, Self::Error>
fn min_by<F>(self, f: F) -> Result<Option<Self::Elem>, Self::Error>
Returns successful element considered minimum by comparator f.
Returns Err(e) on short-circuit failure.
§Examples
use orx_parallel::*;
let x = vec![-3_i32, 0, 1, 5, -10]
.into_par()
.map(Ok::<_, &'static str>)
.into_fallible()
.min_by(|a, b| a.cmp(b));
assert_eq!(x, Ok(Some(-10)));Sourcefn min_by_key<B, F>(self, f: F) -> Result<Option<Self::Elem>, Self::Error>
fn min_by_key<B, F>(self, f: F) -> Result<Option<Self::Elem>, Self::Error>
Returns successful element with minimum key value.
Returns Err(e) on short-circuit failure.
§Examples
use orx_parallel::*;
let x = vec![-3_i32, 0, 1, 5, -10]
.into_par()
.map(Ok::<_, &'static str>)
.into_fallible()
.min_by_key(|x| x.abs());
assert_eq!(x, Ok(Some(0)));Dyn Compatibility§
This trait is not dyn compatible.
In older versions of Rust, dyn compatibility was called "object safety".